环境如下:
1、 centos7.2
2、mysql5.7
1、编辑配置文件
vim /etc/my.cnf
往此文件中添加如下代码
skip-grant-tables
如下图

2、重启mysql服务
service mysqld restart
3、进入mysql
mysql -u root -p
如下图

这里别理会它,直接回车跳过
4、重设密码
use mysql;
update user set authentication_string=password('你的密码') where user='root';
flush privileges;
5、删除my.cnf中的skip-grant-tables
6、然后重启mysql
7、可能上面的修改语句没生效,则可以用下面的语句修改
set password for 'root'@'localhost'=password('123456');
flush privileges;
网友评论