No such file or directory - /var/run/mysqld/mysqld.sock

8,912

Solution 1

Most likely your MySQL service isn't running. The socket in your error is the default location for the MySQL socket in Ubuntu, so unless you compiled MySQL from source or changed the MySQL configuration it should be there.

Try to start MySQL:

sudo /etc/init.d/mysql start

Solution 2

You probably need to check whether: a) mysql is running b) sockets are enabled c) the default socket location is available

So here is how you would go about it: a) check mysql is running

sudo ps -ef | grep -c mysql

If the count returns 0 then mysql is not running. This check will also catch if mysql has been started with safe_mysqld.

If you don't think it is running then you can issue the standard init start script.

sudo /etc/init.d/mysql start

If you check again and the answer is 0 then mysql for some reason is not starting and you have bigger problem. A good place to start is to fire up mysqld from the command line using the bare bones binary call, if something is wrong it should be pushed out to standard error on the console.

b) if the server is running you can check if it has sockets enabled by either checking my.cnf config file or by using netstat

sudo netstat -nalp | grep mysql

This should let you know if sockets are available -> they can be in the state of either CONNECTED or LISTENING. If there are no LISTENING sockets available then it could be that your server is too darn busy to talk to you. But in general if the server is running you should at least have one LISTENING socket.

c) you should check in your my.cnf file to see where the socket location is - in case it does not match the default; and whether it is not commented out.

    [mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock

or

     [client]
socket          = /var/run/mysqld/mysqld.sock
Share:
8,912

Related videos on Youtube

John
Author by

John

We consult and build stuff out of Toronto!

Updated on September 17, 2022

Comments

  • John
    John over 1 year

    I tried to migrate a 5 year old ruby on rails application onto a new server with Ubuntu 8.04, Apache 2 and MySQL 5.

    The application failed to run. When I looked in the error logs, I noticed

    Errno::ENOENT (No such file or directory - /var/run/mysqld/mysqld.sock)
    

    I looked around my new server but can't find a mysqld.sock file. How can I fix this problem?

  • Ahmed I. Elsayed
    Ahmed I. Elsayed over 3 years
    such a stupid bug that bothered me to figure out that mysql ain't running. thanks