MySQL忘记root密码

 1  修改配置文件

vim /etc/my.cnf

[mysqld] 

skip-grant-tables    #添加此条配置,用来跳过授权表

2 重启数据库 

systemctl restart mysqld

3 设置新密码

mysql5.6

update user set password=PASSWORD('新密码') where user='root';

mysql5.7

update user set authentication_string = password('新密码') where user = 'root';

或者
update user set authentication_string = password('新密码'), password_expired = 'N', password_last_chang_changed = now() where user = 'root';

posted @ 2018-10-16 17:25  Sunzz  阅读(204)  评论(0编辑  收藏  举报