当前状态是:
- MySQL 能正常启动
- 但
root已经被设置过认证信息 - 你现在不知道它的有效密码,或者认证插件不匹配
你刚才的结果已经把"现在是空密码"排除了。你贴的启动日志也说明这个库后来一直在正常使用,不是刚初始化的新空库。
现在最稳的处理方式是:直接重置 root 密码。
保留现有数据,重置 root 密码
先停掉当前容器:
bash
docker stop deeptest-mysql
然后用同一份数据目录,临时以"跳过权限表"的方式启动一个恢复容器:
bash
docker run --rm -d \
--name mysql-reset \
-p 3308:3306 \
-v /root/test_software/data/mysql:/var/lib/mysql \
mysql:8.0 \
--skip-grant-tables --skip-networking=0
进入这个临时容器:
bash
docker exec -it mysql-reset mysql -uroot
进去后先执行:
sql
FLUSH PRIVILEGES;
再看看用户表里 root 的 host 和插件:
sql
SELECT user, host, plugin FROM mysql.user WHERE user='root';
然后把密码统一改掉。先执行这两句:
sql
ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'deeptest123456';
ALTER USER 'root'@'%' IDENTIFIED WITH caching_sha2_password BY 'deeptest123456';
如果第二句报 Operation ALTER USER failed,说明没有 'root'@'%',那就忽略,只保留 localhost 那句。
再执行:
sql
FLUSH PRIVILEGES;
退出:
sql
exit
关掉恢复容器:
bash
docker stop mysql-reset
再正常启动原容器:
bash
docker start deeptest-mysql
最后测试登录:
bash
docker exec -it deeptest-mysql mysql -uroot -p
输入:
text
deeptest123456