1、编辑配置文件,vi /etc/my.cnf
在mysqld下增加skip-grant-tables内容
[mysqld]skip-grant-tables
2、wq退出并保存

3、重启mysql服务
systemctl restart mysql

4、mysql重启完成之后直接输入mysql命令进行登录

5、将root的密码更换为123456
mysql> use mysql;mysql> update user set password=password("123456") where user="root";mysql> flush privileges;mysql> quit

6、去掉步骤1中的
skip-grant-tables

7、再次重启mysql服务

8、输入密码进行登录
mysql -uroot -p123456
