请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

Error 1045: Access denied for user 'root'@'172.17.0.1' (using password: YES)

从命令行可以访问master,确认权限也是OK的。

$ mysql -u root -h 192.168.3.3 -P13306 -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.33-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select host,user from mysql.user;
+-----------+---------------+
| host      | user          |
+-----------+---------------+
| %         | root          |
| %         | slave         |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
5 rows in set (0.01 sec)

mysql> 

代码里使用了同样的连接信息:

func init() {
	db, _ = sql.Open("mysql", "root:123456@tcp(192.168.3.3:13306)/fileserver?charset=utf8")
	db.SetMaxOpenConns(1000)
	err := db.Ping()
	if err != nil {
		fmt.Println("Failed to connect to mysql, err:" + err.Error())
		os.Exit(1)
	}
}

但是运行go的时候却报错说连结被拒绝了。。。

$ go run main.go
Failed to connect to mysql, err:Error 1045: Access denied for user 'root'@'172.17.0.1' (using password: YES)
exit status 1

正在回答 回答被采纳积分+3

1回答

xiaomo 2021-03-23 22:12:14

同学你好,这个问题确实比较奇怪。确定只有一处地方连接了mysql吗(如你上面粘贴的代码)?如果实在不行,新创建一个非root账户,重新配置下代码后运行再试试看。

0 回复 有任何疑惑可以回复我~
  • 我也出现了这个问题,报错的ip根本就不是服务器的ip,我也不知道哪里来来的,而且按照老师创建用户也不行
    回复 有任何疑惑可以回复我~ 2021-04-19 16:01:19
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信