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