mysql忘记root密码

1、ssh连接到服务器
2、执行命令
vim /etc/my.cnf

[mysqld]添加以下内容:
skip-grant-tables
3、systemctl restart mysqld
4、mysql -uroot -p
然后回车登录
5、update user
-> set authentication_string=password('123456')
-> where user='root' and host='localhost';
flush privileges
-> ;
6、执行步骤2注释掉加的那句话,重启服务即可。

原文地址:https://www.cnblogs.com/gaoqiao/p/15291123.html