Mysql doesn't start mysqld.sock is missing

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?


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:

socket=/var/lib/mysql/mysql.sock

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


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.

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.