10 May 2012

/var/run/mysqld is removed after each reboot?

After recent upgrade on my Gentoo box I've accidently got /var/run/mysqld directory removed. The socket path pointed there, and, of course, mysqld denied to launch. The same thing happened some time ago on Ubuntu and openSUSE. I've no clue what makes it(mysqld? rc script?) remove the directory. But I've got at least two simple fixes for that and wanna share it in this post.

Fix #1

Just change path to the socket in /etc/mysql/my.cnf and get rid of these upgrade issues:

socket = /tmp/mysqld.sock
I have it in client and mysqld sections.

Fix #2

Change the runlevel script. In Gentoo it looks like the following:

checkconfig() {
    if [ ! -d /var/run/mysqld ] ; then
        checkpath -d -m 755 -o mysql:mysql /var/run/mysqld
    fi
    if [ -z "${MYSQL_PERMS_OK}" ] && [ "$(stat -c %a /var/run/mysqld)" != "755" ] ; then
        ewarn "mysqld run dir is not world readable, you should reset the perms:"
        ewarn "chmod 755 /var/run/mysqld"
        ewarn "To disable this warning, set 'MYSQL_PERMS_OK' in /etc/conf.d/mysql"
    fi
}
start() {
    checkconfig
    # ...
}
You should have got it. checkconfig is called on at the very beginning of /etc/init.d/mysql start handler.

That's it. I hope this saves someone's time.

3 comments :

  1. Thanks! - just what I needed! :-)

    ReplyDelete
  2. In Gentoo after openRC updating to 0.11 faced problem as /var/run migration to /run/
    Some services stopped working. and so did MySQL. Emerged new version from portage. It didn't help.
    Correcting init script from this post solved my problem.

    Added this lines:

    if [ ! -d /var/run/mysqld ] ; then
    checkpath -d -m 755 -o mysql:mysql /var/run/mysqld
    fi

    in /etc/init.d/mysql after:

    checkconfig() {
    wdebug 4 ">>> checkconfig(\"${1}\")"
    local datadir="${1}" pidfile="${2}" socket="${3}"


    Thank you! You saved my time! This realy works and I do hope that this recipe will be added to package init script in the near future.

    ReplyDelete