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