Windows下忘记MySQL数据库root用户密码解决办法

在忘记密码的情况下如何强制修改密码,我在此提供一种办法。

  1. 以超级管理员打开cmd,关闭mysql服务
net stop mysql
  1. 跳过权限验证登录mysql
mysqld --shared-memory --skip-grant-tables
  1. 在新的窗口中登录mysql

使用命令:

mysql -u root -p
无需输入密码,直接回车即可。
  1. 切换到mysql,将密码置空。
use mysql;
update user set authentication_string='' where user='root';

flush privileges;
  1. 设置加密规则并更新新密码,授权(直接复制这些SQL语句你的密码会更新为123456)
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456' PASSWORD EXPIRE NEVER;
alter user 'root'@'localhost' identified by '123456';
grant all privileges on . to "root"@'localhost';
flush privileges;

Was this helpful?

0 / 0

发表回复 0