方法一:

1)    cd /var/lib/mysql

2)    rm -rf mysql

3)   /etc/init.d/mysqld restart

4)   重新设置密码:

echo "grant all on *.* to 'root'@'localhost' identified by '123456';" | mysql -uroot
echo "grant all on *.* to 'root'@'%' identified by '123456';" | mysql -uroot  -p123456

方法二:

1)   service mysqld stop

2)   使用跳过权限检查的方式启动MySQL:

/usr/bin/mysqld_safe   --skip-grant-tables &

3)   重新设置密码:

echo "grant all on *.* to 'root'@'localhost' identified by '123456';" | mysql -uroot
echo "grant all on *.* to 'root'@'%' identified by '123456';" | mysql -uroot  -p123456