参考:https://help.aliyun.com/knowledge_detail/42520.html

  MySQL忘记了root登录密码需要重置

  1,修改配置文件

  一般配置文件路径为/etc/my.cnf 在[mysqld]下增加一行设置免密登录

[mysqld]
skip-grant-tables

   2,重启MySQL

systemctl restart mysqld

   3,免密登录修改密码

mysql

 

USE mysql;
UPDATE user SET Password = password ('password') WHERE User = 'root';
flush privileges;
quit

   退出并且把步骤1设置注释,重启MySQL即可