天天看點

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)

至此: