全部用管理员运行cmd
1.net stop mysql
2.mysqld --console --skip-grant-tables --shared-memory
3.因为步骤2的操作正在占用cmd,重开一个cmd
4.新开的cmd中执行mysql
5.use mysql
6.update user set authentication_string = '' where user='root' ;
string后面是两个单引号,把密码清空
7.quit
8.在之前的cmd中,Ctrl + C 停止cmd
9.net start mysql
10.新cmd中mysql -uroot -p , 按Enter, 出现“Enter password:” , 再按Enter
11.ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码'; 修改密码,注意结尾分号
12.quit
搞定!
来源:CSDN
作者:苜蓿飘飘
链接:https://blog.csdn.net/weixin_44256512/article/details/104439733