After I rebooted my server, everything started up normally except for "mysql", i tried to start it up manually "/etc/init.d/mysql restart" or with "service mysql restart", it fails

In log file it says:

Jul 16 08:13:38 localhost /etc/init.d/mysql[18136]: error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Jul 16 08:13:38 localhost /etc/init.d/mysql[18136]: Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

I checked that path, but i didn't find that socket file, please advise?

  • Note that for starting you shouldn't do restart; use start. Maybe the problem is that the stopping fails so it doesn't even try to start it.
    – wurtel
    Jul 16, 2015 at 11:59
  • same problem using restart or "stop/start", but no problem at "stop", as it is already not running. Jul 16, 2015 at 12:12
  • @wurtel how does that delete the socket file? Nov 25, 2020 at 4:52
  • @jerinho.com if the process that's listening on the socket stops, then the socket also disappears. Don't confuse these sockets with named pipes.
    – wurtel
    Nov 26, 2020 at 13:30

4 Answers 4


To find all socket files on your system run:

sudo find / -type s

My Mysql server system had the socket open at /var/lib/mysql/mysql.sock

Once you find where the socket is being opened, add or edit the line to your /etc/my.cnf file with the path to the socket file:


Sometimes the system startup script that launched the command line executable specifies a flag --socket=path. This flag could override the my.cnf location, and that would result in a socket not being found where the my.cnf file indicates it should be. Then when you try to run the mysql command line client, it will read my.cnf to find the socket, but it will not find it since it deviates from where the server created one. So, Unless you care where the socket resides, just changing the my.cnf to match should work.

If you're super user in the Linux system, based on the above just do this:

kill -9 <pid_of_mysql>

or sometimes you can do this:

pkill -9 mysqld

After you do this you might want to look for a pid file in /var/run/mysqld/ and delete it

Make sure the permissions on your socket is such that whatever user mysqld is running as can read/write to it. An easy test is to open it up to full read/write and see if it still works:

chmod 777 '/var/run/mysqld/mysqld.sock'

If that fixes the issue, you can tailor the permissions and ownership of the socket as needed based on your security settings.

Also, the directory the socket resides in has to be reachable by the user running the mysqld process.

Reference : https://stackoverflow.com/questions/11990708/error-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysq

  • 2
    nothing returned by find / -type s Jul 16, 2015 at 10:07
  • sudo find / -type s You have to run the command as root ,also mind the spacing Jul 16, 2015 at 10:10
  • 1
    yes i did, returned nothing Jul 16, 2015 at 10:46
  • netstat -ln | awk '/mysql(.*)?\.sock/ { print $9 }' Jul 16, 2015 at 11:31
  • 1
    empty result :( Jul 16, 2015 at 11:43

I tried to startup mysql in "Safe Mode" to create the sock file and pid file, but it fails for some error "bind",

  1. I changed the IP address in "bind ip" parameter in my.cnf to localhost
  2. started mysql in safe mode.
  3. restarted mysql in normal mode, and everything went fine.
  • Change bind ip parameter in my.cnf from to localhost save my day
    – Nolwennig
    Jan 5, 2018 at 14:31

yes, as said above locate your socket file first #find / -type s, if you found a mysqld.sock file under /var/run/mysqld/ directory, check whether any instances of mysqld running or not #netstat -anpt | grep 3306 or #ps aux | grep mysqld if you found any running process stop it (#kill -9 pid) and remove the socket file. Then try to restart it and if mysql not creating socket file then try to start it like

#/usr/sbin/mysqld --defaults-file=/etc/mysql/my.cnf --basedir=/usr --datadir=/var/lib/mysql --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock

Also check your my.cnf file (/etc/mysql/my.cnf) and comment the bind-address field, and if you found any skip-network field comment it.


I had a similar problem when I restarted my laptop (Ubuntu 20.04 LTS) there is failure in the start of MySQL. All I know is mysqld.sock is missing.

To find all socket file in a system do

sudo find / -type s

and check if there is mysqld.sock file. If there is mysqld.sock elsewhere then read the solution here.

If there is no mysqld.sock file anywhere then follow along.

mysql by default has mysqld.sock in '/var/run/mysqld/'. If you can't find mysqld.sock anywhere then, check for mysqld directory in '/var/run/'. For me mysqld directory is missing. To get it back, open terminal and do

sudo dpkg-reconfigure mysql-server-*version*

After that mysqld folder should be back at /var/run/. mysqld.sock file is inside mysqld folder. Check the status with sudo service mysql status.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .