您需要确保使用 sudo 命令以 root 身份运行该命令。
我发现这个重置mysql密码的指令效果很好。
按照此过程,您将禁用 MySQL 服务器上的访问控制。所有连接都将具有根访问权限。将服务器从网络中拔出或至少禁用远程访问是一件好事。
要重置您的 mysqld 密码,只需按照以下说明操作:
Stop the mysql demon process using this command :
sudo /etc/init.d/mysql stop
Start the mysqld demon process using the --skip-grant-tables option with this command
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
因为此时您没有检查用户权限,所以禁用网络是最安全的。在 Dapper 中,/usr/bin/mysqld... 不起作用。但是, mysqld --skip-grant-tables 做到了。
start the mysql client process using this command
mysql -u root
from the mysql prompt execute this command to be able to change any password
FLUSH PRIVILEGES;
Then reset/update your password
SET PASSWORD FOR root@'localhost' = PASSWORD('password');
If you have a mysql root account that can connect from everywhere, you should also do:
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';
Alternate Method:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = 'localhost' AND User = 'root';
And if you have a root account that can access from everywhere:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd')
WHERE Host = '%' AND User = 'root';
对于任何一种方法,一旦收到指示查询成功(受影响的一个或多个行)的消息,刷新权限:
同花顺特权;
然后停止 mysqld 进程并以经典方式重新启动它:
sudo /etc/init.d/mysql 停止
须藤 /etc/init.d/mysql 启动