Upload
kranthikiran386
View
215
Download
0
Embed Size (px)
Citation preview
8/8/2019 Running Multiple Instance
1/4
Running multiple instances
Login to your existing mysql instance and run the below statement to create a user.
GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY '*******';FLUSH PRIVILEGES;
Ifyou already have an instance ofMySQL running then youll want to shut it down before
beginning. You can do this at the command prompt with
linux-v0wq:/etc # service mysql stop
Next we need to edit the my.cnf file
First we need to comment out a few lines in the mysqld section
# The MySQL server
[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
8/8/2019 Running Multiple Instance
2/4
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
8/8/2019 Running Multiple Instance
3/4
log-slave-updates
expire-logs-days=7
Next create all the required directories
#mkdir airtel
#mkdir Vodafone_212
#mkdir MTNL
#/var/lib/mysql/airtelCopy 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.
# chown -R mysql:mysql /var/lib/airtel
# chown -R mysql:mysql /var/lib/Vodafone_212
# chown -R mysql:mysql /var/lib/MTNL
Finally we are ready to start up the instances.
# mysqld_multi start
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
linux-v0wq:~ # ps -e | grep "mysql"
12916 ? 00:00:00 mysqld_safe
13014 ? 00:00:00 mysqld
13040 ? 00:00:00 mysqld_safe
8/8/2019 Running Multiple Instance
4/4
13138 ? 00:00:00 mysqld
13156 ? 00:00:00 mysqld_safe
13254 ? 00:00:00 mysqld
To stop both instances just execute the below command.
# mysqld_multi stop
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 reportReporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running