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