If the system services are managed by systemd, the systemd daemon should be aware of the PID file location of process to start/stop/restart it. On a system with systemd support, “override.conf” is used to specify both “PIDFile” and “ExecStart” with PID file location. Any setting of the process ID file in MySQL option file (my.cnf) is ignored.
This post covers the case when we need to create a separate “override.conf” files for multiple MySQL instances management on the same server. In the following configuration file example it is assumed that two MySQL instances named “Server1” and “Server2” are running on a single CentOS/RHEL 7 machine:
MySQL Configuration File (/etc/my.cnf):
[mysqld@server1] server_id = 1 port = 3307 datadir = /home/mysql57/data socket = /home/mysql57/data/mysql_server1.sock log-error = /home/mysql57/data/mysql_server1.err [mysqld@server2] server_id = 2 port = 3308 datadir = /var/lib/mysql socket = /var/lib/mysql/mysql_server2.sock log-error = /var/lib/mysql/mysql_server2.err
Steps to create “override.conf” for these two instances:
1. Stop any existing running MySQL instance.
2. Create a new folder with instance name specified:
$ mkdir /etc/systemd/system/mysqld@[instance-name].service.d
$ mkdir /etc/systemd/system/mysqld@server1.service.d $ mkdir /etc/systemd/system/mysqld@server2.service.d
3. Create “override.conf”:
For instance named “server1”,
$ cd /etc/systemd/system/mysqld@server1.service.d $ touch override.conf
Copy the following lines into override.conf:
[Service] PIDFile=/home/mysql57/data/mysql_server1.pid ExecStart= ExecStart=/usr/sbin/mysqld --defaults-file=/etc/my.cnf --defaults-group-suffix=@server1 --daemonize --pid-file=/home/mysql57/data/mysql_server1.pid $MYSQLD_OPTS
For instance named “server2”,
$ cd /etc/systemd/system/mysqld@server2.service.d touch override.conf
Copy the following lines into override.conf:
[Service] PIDFile=/var/lib/mysql/mysql_server2.pid ExecStart= ExecStart=/usr/sbin/mysqld --defaults-file=/etc/my.cnf --defaults-group-suffix=@server2 --daemonize --pid-file=/var/lib/mysql/mysql_server2.pid $MYSQLD_OPTS
4. Reload the systemd configuration to apply the configuration changes:
# systemctl daemon-reload
5. Launch each of the configured instances:
# systemctl start mysqld@server1 # systemctl start mysqld@server2