The Blog

Running multiple instances of MySQL on the same server. Posted on

Starting point.

Below is another alternative, but this one seems to be a better way to go.

https://www.percona.com/blog/2014/08/26/mysqld_multi-how-to-run-multiple-instances-of-mysql/

Above needs to be done in my.cnf and not the “.d” folders.

Copy /etc/mysql/my.cnf to /etc/mysql/my2.cnf
Also copy conf.d and mysql.conf.d to conf2.d and mysql.conf2.d
Update all the files in them to point to new data location and lock file needs to be in the /tmp/ location.

Pointing to the New Data Location

MySQL has several ways to override configuration values. By default, the datadir is set to /var/lib/mysql in the /etc/mysql/mysql.conf.d/mysqld.cnf file. Edit this file to reflect the new data directory:

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 

Find the line that begins with datadir= and change the path which follows to reflect the new location.

In our case, the updated file looks like the output below:/etc/mysql/mysql.conf.d/mysqld.cnf

. . .
datadir=/var/lib/mysql2
. . .

This seems like the right time to bring up MySQL again, but there’s one more thing to configure before we can do that successfully.

Step 3 — Configuring AppArmor Access Control Rules

We’ll need to tell AppArmor to let MySQL write to the new directory by creating an alias between the default directory and the new location. To do this, edit the AppArmor alias file:

sudo nano /etc/apparmor.d/tunables/alias

At the bottom of the file, add the following alias rule:/etc/apparmor.d/tunables/alias

. . .
alias /var/lib/mysql/ -> /var/lib/mysql2/,
. . .

For the changes to take effect, restart AppArmor:

sudo systemctl restart apparmor

Now we can start new MySQL

shell> mysqld_safe --defaults-file=/etc/mysql/mysql2.cnf &

This entry was posted in Uncategorized. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *



CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code