无法在Ubuntu 16上使用--skip-grant-tables重置root密码 [英] Can't reset root password with --skip-grant-tables on ubuntu 16

查看:433
本文介绍了无法在Ubuntu 16上使用--skip-grant-tables重置root密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试按照 MysqlPasswordReset 重设根密码,但是当我尝试启动服务器时使用--skip-grant-tables,服务器将无法启动

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

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

服务器正在运行

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

停止服务器

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

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

Trying to start with --skip-grant-tables

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

无密码连接

$ 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

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

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

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.

推荐答案

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

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

启动服务器

$ sudo service mysql start

转到袜子文件夹

$ cd /var/run

备份袜子

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

停止服务器

$ sudo service mysql stop

还原袜子

$ sudo mv ./mysqld.bak ./mysqld

启动mysqld_safe

Start mysqld_safe

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

初始化mysql shell

Init mysql shell

mysql -u root

更改密码

FLUSH PRIVILEGES;

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

这篇关于无法在Ubuntu 16上使用--skip-grant-tables重置root密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆