MySQL5.7.9密码重置

MySQL忘记密码


  1. 修改my.cnf
  • vi /etc/my.cnf,添加skip-grant-tables
  1. 重启数据库
  • service mysqld restart
  1. 连接数据库
  • mysql -u root
  1. 修改MySQL root用户的密码
    三行命令分别如下:
    1
    2
    3
    update mysql.user set authentication_string = password('123456') where user='root' and Host = 'localhost';
    flush privileges;
    quit;
  2. 恢复第一步中的修改
  • vi /etc/my.cnf,删除skip-grant-tables