简体   繁体   English

无法重置丢失的MySQL root密码

[英]Unable to reset lost MySQL root password

I've lost the root password and trying to reset it. 我丢失了root密码,并试图重置它。 I have sudo access. 我有sudo访问。 Reading other pages on this, I'm trying the following method using the skip-grant-tables option: 阅读有关此内容的其他页面,我正在尝试使用skip-grant-tables选项使用以下方法:

$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.
$ sudo mysqld --skip-grant-tables &
[1] 17849
$ mysql -u root mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[1]+  Exit 1                  sudo mysqld --skip-grant-tables

I've tried adding the -h 127.0.0.1 option too as I read somewhere else. 当我在其他地方阅读时,我也尝试添加-h 127.0.0.1选项。 I don't know where the mysqld.sock ought to be if it's not where it's trying to find it, I'm a little lost where to go next. 我不知道mysqld.sock应该在哪里,如果它不在试图找到它的地方,我就迷失了下一步。

I am able to enter the MySQL prompt on another MySQL user/pw but that user doesn't have permission to access the "mysql" database to reset the password. 我可以在另一个MySQL用户/ pw上输入MySQL提示符,但是该用户无权访问“ mysql”数据库以重置密码。

Any help? 有什么帮助吗?

Check this question for the same error 检查此问题是否存在相同的错误

And in order to recover the password, you simply have to follow these steps: 并且为了恢复密码,您只需要遵循以下步骤:

  1. Stop the MySQL server process with the command sudo service mysql stop 使用命令sudo service mysql stop停止MySQL服务器进程
  2. Start the MySQL server with the command sudo mysqld_safe --skip-grant-tables --skip-networking & 使用命令sudo mysqld_safe --skip-grant-tables --skip-networking &启动MySQL服务器
  3. Connect to the MySQL server as the root user with the command mysql -u root 使用命令mysql -u root以root用户身份连接到MySQL服务器。

At this point, you need to issue the following MySQL commands to reset the root password: 此时,您需要发出以下MySQL命令来重置root密码:

mysql> use mysql;
​mysql> update user set authentication_string=password('NEWPASSWORD') where user='root';
​mysql> flush privileges;
​mysql> quit

Where NEWPASSWORD is the new password to be used. 其中NEWPASSWORD是要使用的新密码。

  • Restart the MySQL daemon with the command sudo service mysql restart. 使用命令sudo service mysql restart重新启动MySQL守护程序。 You should now be able to log into MySQL with the new password. 现在,您应该可以使用新密码登录MySQL了。

And that's it. 就是这样。 You can now set, reset, and recover your MySQL password. 现在,您可以设置,重置和恢复MySQL密码。

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM