无法在ubuntu 16上使用--skip-grant-tables重置root密码

时间:2021-07-10 11:13:43

I am trying to reset the root password following MysqlPasswordReset but when I try to start the server with --skip-grant-tables the server doesn't start

我试图在MysqlPasswordReset之后重置root密码但是当我尝试使用--skip-grant-tables启动服务器时服务器无法启动

  • Ubuntu 16.04.1 LTS (GNU/Linux 4.4.0-59-generic x86_64)
  • Ubuntu 16.04.1 LTS(GNU / Linux 4.4.0-59-通用x86_64)
  • mysql Ver 14.14 Distrib 5.7.17, for Linux (x86_64)
  • mysql Ver 14.14 Distrib 5.7.17,适用于Linux(x86_64)

Server is running

服务器正在运行

$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Stop server

停止服务器

$ sudo /etc/init.d/mysql stop
[ ok ] Stopping mysql (via systemctl): mysql.service.

Trying to start with --skip-grant-tables

尝试从--skip-grant-tables开始

sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
[1] 9856

Connect with no password

没有密码连接

$ mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[1]+  Exit 1                  sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking

I also tried to start with mysql_safe (error.log is empty)

我也尝试从mysql_safe开始(error.log为空)

sudo mysqld_safe --skip-grant-tables
2017-02-01T16:33:31.382105Z mysqld_safe Logging to syslog.
2017-02-01T16:33:31.383942Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-01T16:33:31.386058Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-01T16:33:31.388009Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

3 个解决方案

#1


49  

I found that the mysql.sock is deleted when the mysql service is stoped and mysqld_safe can't create it (I can't found the reason), so my solution was back the sock folder and restore before start mysqld_safe

我发现当mysql服务停止时mysql.sock被删除而mysqld_safe无法创建它(我找不到原因),所以我的解决方案是在sock文件夹中恢复并在启动之前恢复mysqld_safe

Start server

启动服务器

$ sudo service mysql start

Go to sock folder

去袜子文件夹

$ cd /var/run

Back the sock

回袜子

$ sudo cp -rp ./mysqld ./mysqld.bak

Stop server

停止服务器

$ sudo service mysql stop

Restore the sock

恢复袜子

$ sudo mv ./mysqld.bak ./mysqld

Start mysqld_safe

启动mysqld_safe

$ sudo mysqld_safe --skip-grant-tables --skip-networking &

Init mysql shell

init mysql shell

mysql -u root

Change password

更改密码

FLUSH PRIVILEGES;

SET PASSWORD FOR root@'localhost' = PASSWORD('my_new_password');

#2


3  

pedronalbert's answer above worked for me but the last step is now deprecated and throws the following warning:

pedronalbert上面给出的答案对我有用,但最后一步现在已被弃用并抛出以下警告:

Warning | 1287 | 'SET PASSWORD FOR = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR = '' instead

警告| 1287 | 'SET PASSWORD FOR = PASSWORD('')'已弃用,将在以后的版本中删除。请改用SET PASSWORD FOR =''

Use this command instead:

请改用此命令:

SET PASSWORD FOR root = '<plaintext_password>';

#3


1  

I tried many ways including @pedronalbert 's but still not working.

我试过很多方法,包括@pedronalbert的,但仍然没有工作。

The way I solved it is adding "skip-grant-tables" in /etc/my.cnf then start mysql service and connecting mysql with "mysql -u root" as https://www.codero.com/knowledge-base/content/33/296/en/how-to-reset-your-root-mysql-password.html

我解决它的方法是在/etc/my.cnf中添加“skip-grant-tables”然后启动mysql服务并将mysql与“mysql -u root”连接为https://www.codero.com/knowledge-base/内容/ 33/296 / EN /如何到复位的根-的mysql-password.html

It works in my VM CentOS 7.

它适用于我的VM CentOS 7。

#1


49  

I found that the mysql.sock is deleted when the mysql service is stoped and mysqld_safe can't create it (I can't found the reason), so my solution was back the sock folder and restore before start mysqld_safe

我发现当mysql服务停止时mysql.sock被删除而mysqld_safe无法创建它(我找不到原因),所以我的解决方案是在sock文件夹中恢复并在启动之前恢复mysqld_safe

Start server

启动服务器

$ sudo service mysql start

Go to sock folder

去袜子文件夹

$ cd /var/run

Back the sock

回袜子

$ sudo cp -rp ./mysqld ./mysqld.bak

Stop server

停止服务器

$ sudo service mysql stop

Restore the sock

恢复袜子

$ sudo mv ./mysqld.bak ./mysqld

Start mysqld_safe

启动mysqld_safe

$ sudo mysqld_safe --skip-grant-tables --skip-networking &

Init mysql shell

init mysql shell

mysql -u root

Change password

更改密码

FLUSH PRIVILEGES;

SET PASSWORD FOR root@'localhost' = PASSWORD('my_new_password');

#2


3  

pedronalbert's answer above worked for me but the last step is now deprecated and throws the following warning:

pedronalbert上面给出的答案对我有用,但最后一步现在已被弃用并抛出以下警告:

Warning | 1287 | 'SET PASSWORD FOR = PASSWORD('')' is deprecated and will be removed in a future release. Please use SET PASSWORD FOR = '' instead

警告| 1287 | 'SET PASSWORD FOR = PASSWORD('')'已弃用,将在以后的版本中删除。请改用SET PASSWORD FOR =''

Use this command instead:

请改用此命令:

SET PASSWORD FOR root = '<plaintext_password>';

#3


1  

I tried many ways including @pedronalbert 's but still not working.

我试过很多方法,包括@pedronalbert的,但仍然没有工作。

The way I solved it is adding "skip-grant-tables" in /etc/my.cnf then start mysql service and connecting mysql with "mysql -u root" as https://www.codero.com/knowledge-base/content/33/296/en/how-to-reset-your-root-mysql-password.html

我解决它的方法是在/etc/my.cnf中添加“skip-grant-tables”然后启动mysql服务并将mysql与“mysql -u root”连接为https://www.codero.com/knowledge-base/内容/ 33/296 / EN /如何到复位的根-的mysql-password.html

It works in my VM CentOS 7.

它适用于我的VM CentOS 7。