天天看点

panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

问题描述:

1)图片描述:

执行 start.sh 脚本,goods-srv 注册到 Consul 失败。

panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

2)文字描述:

在云服务器上,使用 Docker 安装 MySQL 8,一段时间以后,访问数据库就出现了密码的问题。

​======​

​​了解开始​

​======​

​:

如果使用 ​

​ mysql -uroot -pZXCzxc123​

​能连接上,说明密码没问题。

否则就是密码错误。此时报错是:

mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)      

要读明白代码提示是什么意思。

​​

​======​

​​了解结束​

​======​

​​。

解决方案:

### 瞪大眼睛看清楚:1b3ddbed 是 mysql 容器ID
[root@iZuf6eojr96v0vnif2uw6qZ target]# docker exec -it 1b3ddbed /bin/bash
root@1b3ddbed7f89:/# mysql -uroot -pZXCzxc123
# ... 省略无关代码
mysql> use mysql;
# ... 省略无关代码
Database changed

mysql> update user set host = '%' where user ='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)      
[root@iZuf6eojr96v0vnif2uw6qZ target]# docker restart 1b3dd
1b3dd
[root@iZuf6eojr96v0vnif2uw6qZ target]# ./start.sh 
starting goods_srv_main
start goods_srv_main success
[root@iZuf6eojr96v0vnif2uw6qZ target]#      
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)
panic: Error 1045: Access denied for user ‘root‘@‘117.61.242.215‘ (using password: YES)

至此: