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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM