title: docker mysql 忘记了密码,2059 - Authentication plugin ‘caching_sha2_password‘ cannot be loaded:报错的解决办法
date: 2023-03-07T14:18:38Z
lastmod: 2023-03-07T14:42:44Z
将docker 中的mysql 配置文件拷贝到外部
docker cp mysql:/etc/mysql/my.cnf /home
修改配置文件
[mysqld]
# 添加这三行
skip-host-cache
skip-name-resolve
skip-grant-tables
#----------
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Custom config should go here
!includedir /etc/mysql/conf.d/
将该配置文件覆盖docker 中mysql 的配置文件(最好在容器里面做个备份)
docker cp my.cnf mysql-liandi:/etc/mysql
重启容器
docker restart mysql
进入目标容器
docker exec -it mysql bash
无密码进入root 账户数据库
mysql -uroot -p
回车进入
mysql中的操作
将密码重置为空密码
update user set authentication_string='' where user='root';
生效配置
flush privileges;
重置新密码(开启远程连接)
ALTER USER ‘root’@‘%’ IDENTIFIED WITH mysql_native_password BY ‘123456’;
flush privileges;
exit;
退出容器,将skip-grant-tables注释,重启mysql容器
exit;
docker restart mysql;
测试验证
标签:配置文件,skip,密码,mysqld,mysql,docker From: https://www.cnblogs.com/duoban/p/17188107.html