1)打开命令提示符,关闭MySQL服务:net stop mysql
2)输入 :mysqld --console --skip-grant-tables --shared-memory
3)保持当前窗口,另开新的cmd窗口,输入mysql,跳过密码登录,进入mysql
4)修改密码 ,转载自https://blog.csdn.net/wolf131721/article/details/93004013
MySql 从8.0开始修改密码有了变化,在user表加了字段authentication_string,修改密码前先检查authentication_string是否为空
①如果不为空
use mysql;
update user set authentication_string='' where user='root';--将字段置为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
②如果为空
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root
注意:
如果出现如下错误
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> GRANT ALL PRIVILEGES ON *.* TO IDENTIFIED BY '123' WITH GRANT OPTION
需要执行
flush privileges;
然后再执行
ALTER user 'root'@'localhost' IDENTIFIED BY 'root';--修改密码为root