[英]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: 并且为了恢复密码,您只需要遵循以下步骤:
sudo service mysql stop
sudo service mysql stop
停止MySQL服务器进程 sudo mysqld_safe --skip-grant-tables --skip-networking &
sudo mysqld_safe --skip-grant-tables --skip-networking &
启动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是要使用的新密码。
And that's it. 就是这样。 You can now set, reset, and recover your MySQL password.
现在,您可以设置,重置和恢复MySQL密码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.