mysql忘记密码如何重置及修改密码

1.先将MySQL停止、

命令:systemctl  stop mysqld       #停掉MySQL

命令:systemctl status mysqld         #查看状态

 2.然后跳过授权表启动MySQL服务程序

这一步主要利用mysqld的 --skip-grant-tables选项

修改my.cnf配置,添加 skip_grant_tables=1启动设置:

打开/etc/my.cnf配置文件

添加skip_grant_tables 一行,然后保存退出

 

 3.然后启动MySQL并查看状态

命令:systemctl  start    mysqld

 

 

 

4.使用mysql命令连接到MySQL服务,重设root的密码

由于前一步启动的MySQL服务跳过了授权表,所以可以root从本机直接登录

在命令行内直接输入mysql即可

 

 

5.进入 mysql> 环境后,通过修改mysql库中user表的相关记录,重设root用户从本机登录的密码:

命令:update mysql.user set authentication_string=password('root')   where user='root' and host='localhost'       #重新设置密码

命令:FLUSH PRIVILEGES;            #刷新授权列表

命令: exit    # 退出mysql

 6.重新以正常方式启动MySQL服务程序,验证新密码

   如果前面是修改/etc/my.cnf配置的方法来跳过授权表,则重置root密码后,应去除相应的设置以恢复正常:

 

 

设置密码命令:
update mysql.user set authentication_string=password('root')   where user='root' and host='localhost'    #重新设置密码
alter user 'root'@'localhost' identified by '123456';
set password for root@localhost=password('1234567');    
 grant all ON *.* TO root@localhost identified by '123qqq...A';

posted @ 2021-01-17 19:35  Res0lve  阅读(1702)  评论(0编辑  收藏  举报