一、停止服务
service mysqld stop
二、增加绕过验证配置
vim /etc/my.cnf
#增加下列配置
skip-grant-tables
三、重启mysql
service mysqld start
四、清空密码
mysql -uroot -p
update mysql.user set authentication_string='' where user='root' and host='localhost';
五、注释步骤三配置,然后重启mysql
vim /etc/my.cnf
#skip-grant-tables
service mysqld restart
六、空密码登录后修改root密码
alter user root@localhost identified by 'root';