3

I was working on an answer to this question—on one of my Ubuntu 12.04.5 development servers—and realized that the MySQL install was not creating mysqld.pid and mysqld.sock files despite their paths being explicitly set in my.cnf like this:

[mysqld]
# 
# * Basic Settings
# 
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking

Why would this happen and what can be done to resolve the issue?

1 Answer 1

7

Even though the locations for mysqld.pid and mysqld.sock are set in my server’s my.cnf, the directory doesn’t exist so those files are never created. This will fix that:

First, create the mysqld/ directory in /var/run/ like this:

sudo mkdir -p /var/run/mysqld/

Then, create a mysqld.pid file with touch:

sudo touch /var/run/mysqld/mysqld.pid

Next, create a mysqld.sock file with touch:

sudo touch /var/run/mysqld/mysqld.sock

Now, change the ownership of the directory and files to mysql:mysql like this:

sudo chown mysql:mysql -R /var/run/mysqld

Finally, the permissions on those files should be:

chmod 755 /var/run/mysqld
chmod 777 /var/run/mysqld/mysqld.sock
chmod 660 /var/run/mysqld/mysqld.pid

And restart MySQL like this to get those files set and created:

sudo service mysql restart

When that’s all done, MySQL will be able to to create the mysqld.pid and mysqld.sock files as expected.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .