• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Configure Separate Override.conf For Multiple MySQL Instances Using Systemd

by admin

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
Note: The instance name should be the same as the one specified in the configuration file.
$ 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

Filed Under: CentOS/RHEL 7, Linux, mysql

Some more articles you might also be interested in …

  1. How to Remove/ Disable Bash shell Command History on Linux
  2. How to Create logical networks to segregate traffic in a data center in RedHat Virtualization (RHV)
  3. Shell/Bash Script to Find Prime Numbers in Linux
  4. lynis Command Examples in Linux
  5. ldd: command not found
  6. How To Add New Disk to An Existing Diskgroup on RAC Cluster or Standalone ASM Configuration
  7. How to Access VNC Server Through A Web Browser in CentOS/RHEL
  8. CentOS / RHEL 6 : How to Change the Volume Group Name for Root Disk Device
  9. lvscan Command Examples in Linux
  10. Complete Guide to Configuring iSCSI in CentOS / RHEL 7

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright