一、停止服務
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';