MySQL版本:mysql-8.0.26-winx64
1. 使用管理员权限打开命令窗口,切换到mysql的bin目录下
2. 在命令行中输入: net stop mysql
3. 待mysql服务停止后,输入: mysqld --shared-memory --skip-grant-tables ,此时命令提示符窗口处于锁定状态,我们重新以管理员权限打开新的命令提示符窗口。
4. 在新的命令提示符窗口输入: mysql -uroot -p 后回车,提示输入密码时直接按回车进入。
5. 输入: use mysql;
6. 输入: update user set authentication_string=’’ where user=‘root’; ,将authentication_string置空。
7. 输入: alter user ‘root’@‘localhost’ identified by ‘newpassword’; newpassword是要设的新密码。
如果提示设置失败,则输入: flush privileges;
8. 再次输入: alter user ‘root’@‘localhost’ identified by ‘newpassword’;
9. 最后输入: flush privileges; 到此,密码已经重置成功了