centos7 mysql5.7 忘记密码找回

1、编辑mysql配置文件。

[root@localhost ~]# vi /etc/my.cnf
2、在[mysqld]配置节下新增 skip-grant-tables。

[mysqld]
skip-grant-tables
3、保存配置文件后,重启mysql服务。
[root@localhost ~]# systemctl restart mysql.service
4、使用mysql无密码命令登录mysql数据库。
[root@localhost ~]# mysql
5、使用下面语句修改root密码,注意和之前版本的mysql语句不太一样。
mysql>update mysql.user set authentication_string=password('新密码') where user='root' ;
mysql>flush privileges ;
mysql>quit
6、编辑mysql配置文件,将之前添加的skip-grant-tables去掉。
7、重启mysql服务。
[root@localhost ~]#systemctl restart mysql.service
原文地址:https://www.cnblogs.com/Xingtxx/p/12831688.html