如何删除或重置 mysql 密码!

如何删除或重置 mysql 密码!

我测试了所有建议的答案,但仍然无法重置或删除密码,甚至无法在 Ubuntu 16.04 上重新安装 mysql db,还有其他想法吗?

#1045 - Access denied for user 'root'@'localhost' (using password: YES)

答案1

  1. 打开终端
  2. sudo mysql -u root
  3. use mysql;
  4. SELECT user, plugin FROM user;
  5. UPDATE user SET plugin = "mysql_native_password" WHERE user = "root" ;
  6. SELECT user, plugin FROM user;
  7. exit
  8. 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';

更改密码成功后,它仍然有效。

参考:

  1. http://ubuntu.flowconsult.at/en/mysql-set-change-reset-root-password/
  2. https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html

相关内容