mysql 8.0 忘记密码

1、停止mysql服务
net stop mysql
2、启用免密登录
mysqld --console --skip-grant-tables --shared-memory (注意,这是8.0版本的写法)
3、打开新窗口登录
mysql -u root
4、修改密码
alter user 'root'@'localhost' identified with mysql_native_password by '新密码';
问题:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
解决:mysql> flush privileges;执行完这句再执行刚才的命令就可以了。

特别注意:好像自版本8以来,很多语法都跟之前的有所差异。所以在百度的时候一定要说明版本号!!否则只会徒劳无功!!

原文地址:https://www.cnblogs.com/lu28/p/14542339.html