天天看点

CentOS7 忘记MySQL密码

最近弄了个阿里云,选的CentOS7系统,装上MySQL之后,重置了密码,两天没用密码就忘记了。

于是搜索了一下相关解决方法

  参考

https://blog.csdn.net/sikefeng/article/details/79597230
  • 第一步
vim /etc/my.cnf
           

加入 skip-grant-tables

CentOS7 忘记MySQL密码
  • 第二步

重启MySQL

systemctl restart mysqld
           
  • 第三步

可以直接进入MySQL,不用输入密码

mysql -uroot -p
           
CentOS7 忘记MySQL密码
  • 第四 步

修改密码

update mysql.user set authentication_string=password("你的密码") where user="root";
           
  • 第五 步

退出数据库,重新编辑my.cnf文件,去除 skip-grant-tables

vim /etc/my.cnf
           
  • 第六步

重启数据库,否则依然是无密码进入模式。