方法一
shell> service mysqld stop
shell> mysqld_safe --skip-grant-tables &
shell> mysql
mysql> UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> \q
shell> mysqladmin -u root -p shutdown
shell> service mysqld start
方法二
shell> service mysqld stop
shell> mysqld --user=root --skip-grant-tables
mysql> update user set authentication_string=password('新密码') where user='root' and Host='localhost';
mysql> FLUSH PRIVILEGES;
mysql> \q