260

While starting mysql server 5.7.17 using mysqld_safe, following error occcours.

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 ?

Rajadip
  • 2,799
  • 2
  • 11
  • 15

6 Answers6

658

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?

Have you tried simply creating this directory yourself, and restarting the service?

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
Matt Clark
  • 27,671
  • 19
  • 68
  • 123
  • 2
    No, I haven't done any changes manually. I will try this by creating directory. Thanks for suggestions – Rajadip Feb 11 '17 at 05:16
  • 25
    It happens on mysql 5.7. When you stop the mysql service /var/run/mysqld gets removed and gets recreated when you start again the service. – Capy Jun 05 '17 at 09:35
  • 4
    Had to use sudo for both – Kasun Rajapaksha Apr 19 '19 at 12:27
  • 2
    @Capy - upvoted - @Matt Clark - you kindly edit your answer to include the infomation that even though the DIR might have been created but it shall be deleted if we run - ```$ sudo /etc/init.d/mysql stop``` , thanks – Rohit Dhankar Sep 16 '19 at 13:17
  • if you're still getting the same error following these steps NOTE that `sudo` will resolve this as this directory is removed once `mysql` is stopped and without `sudo` it will not have access to these folders!!! – Jadeye Jun 09 '20 at 08:29
  • This was also my issue, coming from the directory seemed not to be generated when installing from `sudo apt-get install mysql-server` via Ubuntu – dmanexe Jan 12 '21 at 11:36
105

When I used the code mysqld_safe --skip-grant-tables & but I get the error:

mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

$ 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 Starting mysqld daemon with databases from /var/lib/mysql

If I use $ mysql -u root I'll get :

Server version: 5.7.18-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

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

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:

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

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>

Partha Sen
  • 2,759
  • 1
  • 18
  • 17
  • 10
    since MySQL 5.7.6 the Password column was renamed "authentication_string" Here you can read more about it: https://bugs.mysql.com/bug.php?id=76655 – IberoMedia Feb 04 '18 at 17:04
  • 1
    I take that back. Every single query option that you gave throws a syntax error. But at least I got in with mysqld_safe this time... – Native Coder Sep 19 '20 at 03:06
  • Every who reaches here. On MySQL 8.0.15 (maybe earlier than this too) the PASSWORD() function does not work. Please see https://stackoverflow.com/a/63716361/4153682 and https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html – Gopal Kohli Dec 04 '21 at 19:37
9

Work for me in 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
  • UPDATE:

In the newer versions of MySQL the command is:

  use mysql; # use mysql table
  update user set authentication_string=PASSWORD("") where 
  User='root'; # update password to ""
  update user set plugin="mysql_native_password" where 
  User='root'; 

  flush privileges;
  quit;
Amin
  • 251
  • 2
  • 15
Heli Perez
  • 101
  • 1
  • 3
2

Happened to me.
Message is actually incorrect (and in bad English :-)).

To find out the offending file, I ran this command (as root):
sh -x /etc/init.d/mysqld start

And it printed this:

error: Can't connect to local MySQL server through socket '/mysql-dir/mysql.sock'
Check that mysqld is running and that the socket: '/mysql-dir/mysql.sock' exists!

So it seems that the socket file needs to pre-exist, so I did this, again as root:

cd /mysql-dir
touch mysql.sock
chown mysql:mysql mysql.sock

and then:
service mysqld start

And Voila!

Amir Katz
  • 643
  • 2
  • 10
  • 23
1

See this bug: 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.

smilingfrog
  • 376
  • 3
  • 14
0

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.

It is highly probably that many of us have installed "mysql_secure_installation" as this is a best practice. Navigate to bin directory where mysql_secure_installation exist. It can be found in the /bin directory on Ubuntu systems. By rerunning the installer, you will be prompted about whether to change root database password.

  • But, I think this is to use only secure mysql server.isn't it ? It doesn't make difference in this problem. – Rajadip Mar 01 '17 at 13:17
  • This doesn't help if you've forgotten the root password as you must enter the current password first. – Jistanidiot Dec 18 '17 at 17:45