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

Published on Author JF3 Comments

This is about resetting the MySQL 5.7 root password in Ubuntu 16.04 LTS

You probably tried something like this:

sudo service mysql stop
mysqld_safe --skip-grant-tables &

And then got something like this (stangely, exists is misspelled in the output):

[1] 5599
2018-03-02T21:36:41.292413Z mysqld_safe Logging to syslog.
2018-03-02T21:36:41.294798Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2018-03-02T21:36:41.296902Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

Then you tried to find the socket (takes a while):

sudo find / -type s

And /var/run/mysqld does not exist.

So you start mysql again and search and now it does exist!

sudo service mysql start
sudo find / -type s

[output:]
/run/mysqld/mysqld.sock
/run/dbus/system_bus_socket
/run/acpid.socket
/run/snapd-snap.socket
...

My guess is that mysql_safe can’t create the directory (which appears to be dynamically created when mysql starts). Solution:

sudo mkdir /var/run/mysqld 
sudo chown mysql:mysql /var/run/mysqld

Now run:

sudo service mysql stop
mysqld_safe --skip-grant-tables &
mysql -uroot mysql

When you get to the mysql prompt (don’t forget to change your pw before copy/pasting!!!):

UPDATE mysql.user SET authentication_string=PASSWORD('YOURNEWPASSWORD'), plugin='mysql_native_password' WHERE User='root' AND Host='%';

exit;

then

sudo mysqladmin -S /var/run/mysqld/mysqld.sock shutdown
sudo service mysql start

OTHER SOLUTION (means restarting MySQL a couple times!):

Note: in MySQL 5.7 you may find that my.cnf actually references config files elsewhere:

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

So in my case:

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Under [mysqld] add:

skip-grant-tables

Close the file and restart mysql, then…

sudo service mysql restart
sudo mysql -uroot mysql
(use query above...)

Edit mysqld.conf again, remove the line, then restart MySQL

sudo service mysql restart

Good luck!

 

3 Responses to mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists.

  1. I don’t know where I’m going wrong. I installed mysql and was a little surprised that I wasn’t prompted to set a root password, and then I had awful memories of this happening in the past and having a devil of a job to get things running properly again.
    Anyway, my system seems to have accepted that /var/run/mysqld needed to be created, but the next bit just presents me with the following output:

    $ mysqld_safe –skip-grant-tables &
    [1] 3268
    padi@Efnisien:~$ 2019-09-28T18:52:57.702623Z mysqld_safe Logging to syslog.
    2019-09-28T18:52:57.707595Z mysqld_safe Logging to ‘/var/log/mysql/error.log’.
    /usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied
    2019-09-28T18:52:57.711485Z mysqld_safe Directory ‘/var/run/mysqld’ for UNIX socket file don’t exists.
    /usr/bin/mysqld_safe: 152: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied

    Which just brings me back to the original issue, I still can’t set up a password that I know rather than the one used by the system that it won’t tell anyone what it is.

    Maybe I should just have installed mariaDB?

    • After installing MySQL/MariaDB you should run:

      mysql_secure_installation

      This will set the root password, get rid of anonymous users and a test db.

      When it asks you for the initial password just hit enter. You will then set a password later.

      p.s. I often forget to add sudo to my references, so make sure to do that (or just do sudo -i and then you don’t have to type it in all the time)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.