I have this error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2 "No such file or directory")

Does anyone know what is wrong? It seems it isn't installing mysqld.sock when I run apt-get install mysql-server. I tried find / -name "mysqld.sock" but it can't find anything. How can I get mysqld.sock?

  • Did you start the mysql server? Is it configured to use a unix socket at that path?
    – Shawn
    Aug 12, 2018 at 23:14

3 Answers 3


It should not install mysqld.sock. This file is a unix socket, it doesn't refer to a byte stream on your hard disk.

It is more like a TCP port: programs can listen here, and other programs can connect it to communicate with it. The only significant different is that TCP ports are identified by a number between 1 and 65535. Unix sockets are identified by their path, like /var/run/mysql/mysqld.sock.

mysqld.sock is created by the mysql daemon on start, and it is removed (or, becomes un-connectable) if this daemon stops.

This message is given by some client process, trying to connect your mysqld on this socket without success.

Its most likely reason is that the mysqld doesn't run.

Why it doesn't run? Try to start it (systemctl start mysqld) and check the /var/log/mysql* .

  • in errror.log i've got this error. 2018-08-13 10:43:09 139999537754688 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 98: Address already in $2018-08-13 10:43:09 139999537754688 [ERROR] Do you already have another mysqld server running on port: 3306 ? 2018-08-13 10:43:09 139999537754688 [ERROR] Aborting Aug 13, 2018 at 8:45
  • Check what is listening on that socket with an lsof -n -P|grep -F 3306|grep -F LISTEN.
    – peterh
    Aug 13, 2018 at 14:18

/var/run/mysqld/mysqld.sock is created on MySQL service startup and deleted on stop.

Its missing because SQL has an issue starting.

Most common reason: Your drive is full.


Just try to execute the following command

It's the same problem that I faced recently when I tried to install maraidb, and it wouldn't start.

I used this command : service mariadb start .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.