0

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

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

Add this to /etc/my.cnf

[mysqld]
socket=/tmp/mysql.sock

/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
/usr/bin/mysqld_safe

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

safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-/var/lib/mysql/mysql.sock}}
# 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 ]
then
  mkdir $mysql_unix_port_dir
  chown $user $mysql_unix_port_dir
  chmod 755 $mysql_unix_port_dir
fi

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. – Anatoliy Gusarov Mar 21 '14 at 11:49
  • I don't understand why mysqld doesn't have permissions to write to /tmp. =( – Anatoliy Gusarov Mar 21 '14 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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