MySQL no longer restarting correctly after unclean reboot on CentOS 6?

I’ve got a Smörgåsbord of CentOS servers of varying version and patch status; 4 through 6, i386, x86_64, up to date, not up to date, etc.  In any case, sometimes they overload and have to be reset.  This is not typically a problem, but recently the CentOS 6 servers began to have an issue where after reset, MySQL would fail to start.

At this point in time, I’m not sure who changed what exactly, but I determined the issue is that prior to the CentOS 6 package mysql-server-5.1.71-1.el6.x86_64, an unclean shutdown of MySQL would not be a problem at reboot.  Once that package was installed, if /var/lib/mysql/mysql.sock already exists, even if it’s not in use by any running daemon, MySQL will fail to start.  In prior versions, even if the file was there, MySQL would still start anyway.

The temporary fix until it’s permanently committed to the next mysql-server update, is:

  1. Edit /etc/init.d/mysqld
  2. By default, lines 111 through 122 will look like this if you’re running mysql-server-5.1.71-1.el6:
            # Pass all the options determined above, to ensure consistent behavior.
            # In many cases mysqld_safe would arrive at the same conclusions anyway
            # but we need to be sure.  (An exception is that we don't force the
            # log-error setting, since this script doesn't really depend on that,
            # and some users might prefer to configure logging to syslog.)
            # Note: set --basedir to prevent probes that might trigger SELinux
            # alarms, per bug #547485
            if [ -S "$socketfile" ] ; then
                echo "Another MySQL daemon already running with the same unix socket."
                action $"Starting $prog: " /bin/false
                return 1
  3. Eliminate those lines and add this in their place:
            # We check if there is already a process using the socket file,
            # since otherwise this init script could report false positive
            # result and mysqld_safe would remove the socket file, which
            # actually uses a different daemon.
            if fuser "$socketfile" &>/dev/null ; then
                echo "Socket file $socketfile exists. Is another MySQL daemon already running with the same unix socket?"
                action $"Starting $prog: " /bin/false
                return 1
  4. Now when mysqld is started, if a socket exists but is not in use, mysqld will be started regardless and will make use of it. If it does exist and there actually is something attached to it, the init script will just report FAILED like normal if MySQL is already running.

Solution was taken from the redhat bug report on this issue:

Leave a Reply

Your email address will not be published. Required fields are marked *