I have CentOS running on virtual machine on my desktop. When my desktop unexpectedly restarts (blue screen, power failure, restart after updates), virtual machine faces the same problem - unexpected shutdown. When VM starts again, /var/lib/mysql/=mysql.sock file (0 bytes) should be deleted, then mysqld service can be started.

Is there any way to avoid manual deletion of this file? Boot script

1 Answer 1


The only way to avoid manual deletion is relocate mysql.sock

Add this to /etc/my.cnf


/tmp would be a good choice since /tmp gets wiped out on each server reboot

Make sure mysqld has chmod permission to write mysql.sock to /tmp

Give it a Try !!!

UPDATE 2014-03-21 11:37 EDT

If you cannot get /tmp/mysql.sock to be made, there is a hack you can try.

Run which mysqld_safe

This will tell you where the mysqld_safe is located. When I run it I get

sh-4.1# which mysqld_safe

Open the file in vi, got lines 612-620. I see this

# Make sure that directory for $safe_mysql_unix_port exists
mysql_unix_port_dir=`dirname $safe_mysql_unix_port`
if [ ! -d $mysql_unix_port_dir ]
  mkdir $mysql_unix_port_dir
  chown $user $mysql_unix_port_dir
  chmod 755 $mysql_unix_port_dir

You could add this line before it

rm -f /var/lib/mysql/mysql.sock

This might do it for you

CAVEAT : Remember, this is a hack. Should mysql not be able to start for you, I will disavow any knowledge of your actions going forward.

  • Make sure mysqld has chmod permission to write mysql.sock to /tmp - How to? /tmp has 41777 permissions. But mysqld service doesn't starts. Commented Mar 21, 2014 at 11:49
  • I don't understand why mysqld doesn't have permissions to write to /tmp. =( Commented Mar 21, 2014 at 15:11

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.