【发布时间】:2021-05-05 14:03:14
【问题描述】:
我已经在 Debian 10 Linux 服务器上安装了带有 Galera 集群的 MariaDB 10.3。
我创建了一个用户 ueda 并授予所有权限,如下所示:
MariaDB [koshinto]> show grants for 'ueda'@'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for ueda@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `ueda`@`localhost` IDENTIFIED BY PASSWORD '*923D7E4A76755E0B4924C29266AFA3E675D990DC' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
我可以使用用户ueda登录并发出sql命令如下:
ueda@scw-a:~$ mariadb -u ueda -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 169
Server version: 10.3.27-MariaDB-0+deb10u1 Debian 10
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use koshinto
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [koshinto]> select * from test;
+----------+------------------------------+
| bindid | bind |
+----------+------------------------------+
| kerokero | {"kero":"kerokero","aho":20} |
+----------+------------------------------+
1 row in set (0.001 sec)
但是,从下面的 go 代码来看,
package main
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"log"
)
func main() {
log.SetFlags(log.Lshortfile)
db, err := sql.Open("mysql", "ueda:somepassword@/koshinto")
defer db.Close()
if err != nil {
log.Println(err)
} else {
_, err := db.Query("select * from test") //
if err != nil {
log.Println(err)
}
}
}
即使在同一台服务器上使用相同的用户和密码,也会出现“拒绝访问”错误。
ueda@scw-a:~$ go run mysql.go
mysql.go:18: Error 1045: Access denied for user 'ueda'@'localhost' (using password: YES)
【问题讨论】:
-
注意:千万不要使用
go run <file>.go