Login to your existing mysql instance and run the below statement to create a user.
If you already have an instance of MySQL running then you’ll want to shut it down before
beginning. You can do this at the command prompt with…
[mysqld]
#port = 3306
#socket = /var/lib/mysql/mysql.sock
#datadir = /var/lib/mysql/
Add the lines below and the mysqld line tells the mysqld_multi script the MySQL binary to use.
[mysqld_multi]
mysqld=/usr/bin/mysqld_safe
mysqladmin=/usr/bin/mysqladmin
log=/var/log/mysqld_multi.log
user=multi_admin
password=******
Add the below line to create 3 instances. It is critical that each instance has its own unique values or
the server will fail to start or your data could be corrupted.
[mysqld1]
server-id=1001
port=3306
datadir=/var/lib/mysql/airtel
pid-file=/var/lib/mysql/mysqld.pid
socket=/var/lib/mysql/mysql.sock
user=mysql
log-err=/var/log/airtel.err
log-bin=airtel-bin
log-slave-updates
expire-logs-days=7
[mysqld2]
server-id=1002
port=3307
datadir=/var/lib/mysql/vodafone_212
pid-file=/var/lib/mysql/mysqld.pid2
socket=/var/lib/mysql/mysql.sock2
user=mysql
log-err=/var/log/vodafone_212.err
log-bin=vodafone_212-bin
log-slave-updates
expire-logs-days=7
[mysqld3]
server-id=1003
port=3308
datadir=/var/lib/mysql/mtnl
pid-file=/var/lib/mysql/mysqld.pid3
socket=/var/lib/mysql/mysql.sock3
user=mysql
log-err=/var/log/mtnl.err
log-bin=mtnl-bin
log-slave-updates
expire-logs-days=7
#mkdir airtel
#mkdir Vodafone_212
#mkdir MTNL
# /var/lib/mysql/airtel
Copy the mysql database files from the original instance to the instances database directory. Then
this instance will have all of the same users as instance 1
# cp -r /var/lib/mysql/mysql airtel/
# cp -r /var/lib/mysql/mysql Vodafone_212/
# cp -r /var/lib/mysql/mysql MTNL/
Change the owner of the data directory to the mysql user so the instance can read them.
To check both instances have started correctly execute the below command.
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
You can see that the mysqld_multi script has started multiple mysql processes with the following
commands
We are also able to control individual instances by referring to the assigned number.
# mysqld_multi stop 1
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is running
# mysqld_multi start 1
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running