mysql 5.7忘记密码,如何重置?别着急,往这里看

1 免密码登陆

  • 编辑mysql配置文件:vi /etc/my.cnf
  • mysqld模块中添加:skip-grant-tables
  • 重启服务,使配置生效: service mysqld restart;
    mysql 5.7忘记密码,如何重置?别着急,往这里看

2 旧密码置空

  • 输入mysql -u root -p :提示输入密码,直接回车
  • 选择mysql库:use mysql
  • 清空密码:update user set authentication_string = '' where user = 'root';
  • 退出: exit

3 恢复密码验证

  • 删除第一步配置文件中添加的语句:skip-grant-tables
  • 重启服务 service mysqld restart

4 修改密码

  • 登入mysql:mysql -u root -p 直接回车登录
  • 修改密码:ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';

5 常见问题

1 修改密码时报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

  • 错误原因:密码不符合mysql安全策略
  • 解决办法:关闭安全策略检查,具体就是在my.cnf末尾添加validate_password=off

2 重启服务报错:Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.

  • 错误原因:配置文件改错了,重启失败
  • 解决办法:重新修改配置文件