mysql忘记密码的终极解决方案(docker-compose)

MYSQL8的安全性能有所提高,装好后,各种不适应,需要各种调试。

1. 首先,root密码忘记或是更改,操作步骤:
vi mysql/config/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables=1 保存并且退出vi。

docker-compose restart
进入bash,运行mysql -uroot -p ,回车,直接进入。

下面很重要,特别是flush privileges,千万别忘。在之前的版本中,密码字段的字段名是 password,5.7版本以后改为了 authentication_string。

另外,初始化root密码不要太复杂,就root就行,然后到步骤4,你再改复杂点的密码。

update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';

FLUSH PRIVILEGES;

3.回到my.cnf ,删除skip-grant-tables

4.继续进入bash,运行mysql -uroot -p ,回车进入

alter user 'root'@'localhost' identified by '你的密码'; alter user 'root'@'%' identified by '你的密码';

FLUSH PRIVILEGES;

5.搞定

posted @ 2021-12-16 11:12  李济宏(Amadeus)  阅读(242)  评论(0编辑  收藏  举报