docker部署mysql5.7後登錄時出現Access denied for user 'root'@'localhost' (using password: YES)的解決方法

1、先進去容器中安裝vim工具

docker exec -it mysql bash
apt-get update
apt-get -y install vim

2、修改/etc/mysql/conf.d/docker.cnf文件,添加:skip-grant-tables

[mysqld]
skip-host-cache
skip-name-resolve
skip-grant-tables

3、退出,重啓mysql容器

docker restart mysql

4、再次進入容器mysql -uroot -p進入mysql後

mysql> use mysql;
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

mysql> update mysql.user set authentication_string = password("root1234") where user="root";
Query OK, 2 rows affected, 1 warning (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 1

mysql> exit

5、刪除/etc/mysql/conf.d/docker.cnf文件中添加的skip-grant-tables,再重啓容器

6、再次進入mysql就正常了。

參考:https://blog.csdn.net/weixin_48226988/article/details/112681407

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章