(1)打开cmd 窗口,执行net stop mysql命令,停止MySQL服务
(2)执行 mysqld --console --skip-grant-tables --shared-memory 命令开启跳过密码验证登录
(3)新打开一个cmd窗口,无密码登录MySQL:mysql -u root -p
(4)重置密码为空
use mysql
update user set authentication_string=’’ where user=‘root’;
(5)执行exit退出mysql
(6)关闭使用mysqld --console --skip-grant-tables --shared-memory 命令的cmd窗口,
(7)cmd重新启动MySQL服务:net start mysql
(8)此时可以无密码状态登录MySQL,输入登录命令:mysql -u root -p
(9)ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘新密码’;
但此时会报错ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
(10)执行第9步骤之前先执行flush privileges;刷新权限再修改密码
(11)退出MySQL后重新输入登录命令mysql -u root -p,使用新密码登录即可