Running Multiple MySQL Instances on CentOS 6 / RHEL 6

There are many reasons why a server admin may want to run multiple instances of MySQL on the same physical server. These could include consolidating physical servers, increasing uptime per product, or to fully utilize existing hardware. In our case, we want to set up a separate MySQL instance to house Zabbix database. Zabbix is an open source systems monitoring platform. We want this database to remain online as much as possible, even when we are performing maintenance to our main MySQL database.

Spinning up a separate MySQL instance isn’t difficult at all. We will walk you though the steps you need to take and files you need to modify. As always, back up your system before starting. We will not be held responsible for any data loss or corruption to your system. Throughout the document, we will be referring to the new database as “mysqlzabbix”. Our server is running CentOS 6.5 x64 with MySQL 5.6.10 x64.

Step 1
To begin, we’ll need to create a data directory for the new instance and make sure the folder is owned by the mysql user.

01

Step 2
Next, make a new copy of the MySQL configuration file. In our case, we are calling it “myzabbix.cnf”. After it’s copied, open it for editing.

02

Step 3
This will be the core configuration of your MySQL instance. You will need to update the data directories, and error log location. In addition, pick a port number you would like to run your MySQL instance on. For our configuration, we started with the default configuration file and modified it to our liking.

03

Step 4
Next, make a copy of the startup script. We will be making several edits to this file. First, find and replace all occurrences of “my.cnf” with “myzabbix.cnf”. There will be quite a few.

04

Second, locate the line that begins with “$bindir/mysqld_safe”. In our init script, it is line 283. Change it to the code below. This will point it to our new configuration file.

05

The last edit to this file will be a flag to allow MySQL to read our new configuration file when parsing server arguments. You’ll want to find the “parse_server_arguments” line (around line 256)and change it to:

08

Step 5
Once all the init script changes are in place, it’s time to initialize the new data directory with a clean database.

06

Step 6
Finally, it’s time to start your new database instance!

07

Step 7
Once your database starts, make sure to set your root password. Pick a nice complex secure one.

09

Step 8
Log in to your database to confirm it’s running and double check the port it’s operating on.

10

Step 9
Finally, set your instance to run on startup.

11

Leave a Reply