编辑Mysql配置文件/etc/my.cnf
nano /etc/my.cnf
找到[mysqld],在下面添加一行skip-grant-tables
重启MySQL
service mysqld restart
root用户登录MySQL,提示密码直接回车
mysql -u root -p
修改root密码,并刷新权限
update mysql.user set authentication_string=password(‘新密码’) where user=’root’ and host=’localhost’;
flush privileges;
退出MySQL,注释掉my.cnf中的skip-grant-tables
重启MySQL
service mysqld restart