1、修改 /etc/my.cnf 配置文件
vim /etc/my.cnf 添加 skip-grant-tables
2、重啓mysql服務
service mysqld restart
3、輸入用戶,直接回車進去
4、進入mysql數據庫
5、修改密碼
update user set authentication_string=password("new password") WHERE user='root' ' and host = 'localhost';
6、去除第一步中的配置 skip-grant-tables,重啓mysql服務就好了