MySQL8.0 Password Forgot lost, reset method

first step

vim /etc/my.cnf ,添加如下:skip-grant-tables,保存退出

The second step

systemctl  restart  mysqld   ##重新启动mysql服务。

third step

此时的mysql数据库,已经没有了验证,直接回车进入:
use mysql;
update user set authentication_string='' where user='root';
##这两个命令让数据库密码为空。

the fourth step

vim /etc/my.cnf 
将my.cnf里skip-grant-tables注释掉后重启服务:

1.--skip-grant-tables 直接启动时mysql服务来跳过权限认证时用的参数。
2.skip-grant-tables是要写入到/etc/my.cnf配置文件当中来跳过权限认证。

the fifth step

密码已置空,所以无密码状态登录mysql: mysql>mysql -uroot

Step Six

修改新密码: mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘新密码’;
【MySQL完整的初始密码规则可以通过如下命令查看: mysql> show variables like ‘validate_password%’;】

last step

 验证更改后密码登录:
输入quit,退出当前登录;
输入登录命令:mysql -u root -p
输入密码,成功登录;
到此,重置密码结束。

QQ (2594676962), bloggers often online

Released three original articles · won praise 2 · views 75

Guess you like

Origin blog.csdn.net/weixin_43740875/article/details/104626133