我测试了所有建议的答案,但仍然无法重置或删除密码,甚至无法在 Ubuntu 16.04 上重新安装 mysql db,还有其他想法吗?
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
答案1
- 打开终端
sudo mysql -u root
use mysql;
SELECT user, plugin FROM user;
UPDATE user SET plugin = "mysql_native_password" WHERE user = "root" ;
SELECT user, plugin FROM user;
exit
service mysql restart
答案2
您可以在 Ubuntu Linux 上更新 MySQL 根密码。输入以下几行:
1. Stop the MySQL Server: sudo /etc/init.d/mysql stop
2. Start the mysqld configuration: sudo mysqld --skip-grant-tables &
3. Login to MySQL as root: mysql -u root mysql
4. Replace "newpassword" with your new password:
UPDATE
mysql.user
SET
Password = PASSWORD('newpassword')
WHERE
User = 'root';
FLUSH PRIVILEGES;
exit;
Note: on some versions, if password column doesn't exist, you may want to try: UPDATE user SET authentication_string=password('newpassword') WHERE user='root';
更改密码成功后,它仍然有效。
参考: