mysql8忘记登录密码时,修改密码方法

时间:2023-03-09 20:24:22
mysql8忘记登录密码时,修改密码方法

一、停止mysqld进程

systemctl stop mysqld.service

二、修改/etc/my.cnf(在mysqld选项添加skip-grant-tables),设置免密码登录:

vim /etc/my.cnf

mysql8忘记登录密码时,修改密码方法

三、登录mysql并修改root密码为空:

update mysql.user set authentication_string=''  where User='root';

四、退出mysql,去掉/etc/my.cnf上的skip-grant-tables,上述步骤二添加的配置

五、再次登录mysql,密码为空,修改root用户密码为新密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Zcz123456!';

六、退出后重新登录,输入新的密码即可成功登录