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-lockingWhy would this happen and what can be done to resolve the issue?
1 Answer
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.pidNext create a mysqld.sock file with touch:
sudo touch /var/run/mysqld/mysqld.sockNow change the ownerships of the directory and files to mysql:mysql like this:
sudo chown mysql:mysql -R /var/run/mysqldAnd restart MySQL like this to get those files set and created:
sudo service mysql restartWhen that’s all done, MySQL will be able to to create the mysqld.pid and mysqld.sock files as expected.