本人环境为MySQL 5.7 + CentOS 6.3。
1. 编辑MySQL配置文件/etc/my.cnf
找到[mysqld],在下面添加一行skip-grant-tables

2. 重启MySQL
service mysqld restart

3. root用户登录MySQL,提示密码直接回车
mysql -uroot -p

4. 修改root密码,并刷新权限
update mysql.user set authentication_string=password('新密码') where user='root' and host='localhost';
flush privileges;

5. 退出MySQL,并编辑MySQL配置文件/etc/my.cnf
6. 重启MySQL
service mysqld restart7. 使用新密码登录,测试修改成果
注意:如果MySQL是5.5,则修改密码的语句是update mysql.user set password=password('123456') where user='root' and host='localhost';