1.切換數據庫
use mysql;
2.執行命令修改密碼
update user set password=password('root') where user='root';
//5.7 以後版本執行上面命令報錯可以嘗試以下語句:
update user set authentication_string=password('123456') where user='root';
3.刷新權限
flush privileges;
//可能會出現的異常
ERROR 1820 (HY000): You must reset your password using ALTER USER statement;
//解決辦法(執行以下命令):
alter user user() identified by "root";
5、還原配置文件,重啓Mysql服務
[mysqld]
#skip-grant-tables
//重啓服務
service mysqld restart