简体   繁体   English

UNIX 套接字文件的 mysqld_safe 目录 '/var/run/mysqld' 不存在

[英]mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists

While starting mysql server 5.7.17 using mysqld_safe, following error occcours.使用 mysqld_safe 启动 mysql server 5.7.17 时,出现以下错误。

2017-02-10T17:05:44.870970Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.872874Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2017-02-10T17:05:44.874547Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

How to fix it?如何解决?

It seems odd that this directory was not created at install - have you manually changed the path of the socket file in the my.cfg?这个目录不是在安装时创建的,这似乎很奇怪——你是否手动更改了 my.cfg 中套接字文件的路径?

Have you tried simply creating this directory yourself, and restarting the service?您是否尝试过自己简单地创建这个目录,然后重新启动服务?

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld

When I used the code mysqld_safe --skip-grant-tables & but I get the error:当我使用代码mysqld_safe --skip-grant-tables &但我得到错误:

mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists. mysqld_safe UNIX 套接字文件的目录“/var/run/mysqld”不存在。

$ systemctl stop  mysql.service
$ ps -eaf|grep mysql
$ mysqld_safe --skip-grant-tables &

I solved:我解决了:

$ mkdir -p /var/run/mysqld
$ chown mysql:mysql /var/run/mysqld

Now I use the same code mysqld_safe --skip-grant-tables & and get现在我使用相同的代码mysqld_safe --skip-grant-tables &并得到

mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql mysqld_safe 使用 /var/lib/mysql 中的数据库启动 mysqld 守护进程

If I use $ mysql -u root I'll get:如果我使用$ mysql -u root我会得到:

Server version: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)服务器版本:5.7.18-0ubuntu0.16.04.1(Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates.版权所有 (c) 2000、2017,Oracle 和/或其附属公司。 All rights reserved.版权所有。

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Oracle 是 Oracle Corporation 和/或其附属公司的注册商标。 Other names may be trademarks of their respective owners.其他名称可能是其各自所有者的商标。

Type 'help;'输入“帮助;” or '\h' for help.或 '\h' 寻求帮助。 Type '\c' to clear the current input statement.输入'\c'清除当前输入语句。

mysql>数据库>

Now time to change password:现在是时候更改密码了:

mysql> use mysql
mysql> describe user;

Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A读取表信息以完成表名和列名您可以使用 -A 关闭此功能以更快地启动

Database changed数据库已更改

mysql> FLUSH PRIVILEGES;
mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('newpwd');

or If you have a mysql root account that can connect from everywhere, you should also do:或者如果你有一个可以从任何地方连接的 mysql root 帐户,你还应该这样做:

UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

Alternate Method:替代方法:

   USE mysql
   UPDATE user SET Password = PASSWORD('newpwd')
   WHERE Host = 'localhost' AND User = 'root';

And if you have a root account that can access from everywhere:如果你有一个可以从任何地方访问的根帐户:

 USE mysql
 UPDATE user SET Password = PASSWORD('newpwd')
 WHERE Host = '%' AND User = 'root';`enter code here

now need to quit from mysql and stop/start现在需要quit mysql 并停止/启动

FLUSH PRIVILEGES;
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

now again ` mysql -u root -p' and use the new password to get现在再次 `mysql -u root -p' 并使用新密码获取

mysql>数据库>

Work for me in CentOS:在 CentOS 中为我工作:

$ service mysql stop
$ mysqld --skip-grant-tables &
$ mysql -u root mysql

mysql> FLUSH PRIVILEGES;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';

$ service mysql restart

Happened to me.发生在我身上。
Message is actually incorrect (and in bad English:-)).消息实际上是不正确的(而且英语不好:-))。

To find out the offending file, I ran this command (as root):为了找出有问题的文件,我运行了这个命令(作为 root):
sh -x /etc/init.d/mysqld start sh -x /etc/init.d/mysqld 启动

And it printed this:它打印了这个:

error: Can't connect to local MySQL server through socket '/mysql-dir/mysql.sock'错误:无法通过套接字“/mysql-dir/mysql.sock”连接到本地 MySQL 服务器
Check that mysqld is running and that the socket: '/mysql-dir/mysql.sock' exists!检查 mysqld 是否正在运行并且套接字:'/mysql-dir/mysql.sock' 存在!

So it seems that the socket file needs to pre-exist, so I did this, again as root:所以套接字文件似乎需要预先存在,所以我再次以 root 身份执行了此操作:

cd /mysql-dir cd /mysql目录
touch mysql.sock触摸 mysql.sock
chown mysql:mysql mysql.sock chown mysql:mysql mysql.sock

and then:接着:
service mysqld start服务 mysqld 启动

And Voila!瞧!

See this bug: https://bugs.launchpad.net/ubuntu/+source/mysql-5.6/+bug/1435823看到这个错误: https ://bugs.launchpad.net/ubuntu/+source/mysql-5.6/+bug/1435823

There seems to be a temporary fix there那里似乎有一个临时修复

Create a newfile /etc/tmpfiles.d/mysql.conf:

# systemd tmpfile settings for mysql
# See tmpfiles.d(5) for details

d /var/run/mysqld 0755 mysql mysql -

After reboot, mysql should start normally.

You may try the following if your database does not have any data OR you have another away to restore that data.如果您的数据库没有任何数据,或者您有另一个数据库可以恢复该数据,您可以尝试以下操作。 You will need to know the Ubuntu server root password but not the mysql root password.您将需要知道 Ubuntu 服务器 root 密码,但不需要知道 mysql root 密码。

It is highly probably that many of us have installed "mysql_secure_installation" as this is a best practice.我们中的许多人很可能已经安装了“mysql_secure_installation”,因为这是最佳实践。 Navigate to bin directory where mysql_secure_installation exist.导航到 mysql_secure_installation 所在的 bin 目录。 It can be found in the /bin directory on Ubuntu systems.它可以在 Ubuntu 系统的 /bin 目录中找到。 By rerunning the installer, you will be prompted about whether to change root database password.通过重新运行安装程序,系统将提示您是否更改根数据库密码。

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

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