mysql multi-port implementation of multiple instances and mysqld_multi management

Sometimes, it is necessary to open multiple ports of mysql on one machine, for example, multiple ports realize the separation of read and write of the database. This article explains the multi-port opening of mysql and how mysqld_multi manages the multi-port of mysql.

Conventional practice:
1. First, make a copy of the my.cnf configuration file, and of course rename it when you open several ports (3306 can also be used directly).
cp /etc/my.cnf /etc/my3306.cnf
cp /etc/my.cnf /etc/my3307.cnf 

2. Modify my3306.cnf, my3307.cnf file and change the default 3306 port to 3307 (according to your own my.cnf is modified, some parameters are skipped). 
For example:
[client]
port = 3307
socket = /tmp/mysql3307.sock [mysqld] port = 3307 socket = /tmp/mysql3307.sock basedir=/usr/local/mysql datadir=/usr/local/mysql/var3307 3. Create a database to specify the directory for storing data (note that the group must be modified to mysql, add a few plus a few, 3306 can directly use the ready-made var) mkdir /usr/local/mysql/var3307 4. Initialize the database
 










/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/var3307/ --user=mysql --basedir=/usr/local/mysql 

5. To start mysql, specify the .cnf file and directory start
/usr/local/mysql/bin/mysqld_safe --defaults-extra-file=/etc/my3306.cnf --datadir=/usr/local/mysql/var --user=mysql &
/usr/local/mysql/ bin/mysqld_safe --defaults-extra-file=/etc/my3307.cnf --datadir=/usr/local/mysql/var3307 --user=mysql & 

6. Log in to mysql
mysql -S /tmp/mysq3307.sock // sock login
mysql -uroot -p -h127.0.0.1 -P3307 //Port number login

7, stop MYSQL, pass the corresponding sock file.
/usr/local/mysql/bin/mysqladmin -uroot -S /tmp/mysql3307.sock shutdown

At this point, you can come to an end. But there is a trouble in this, that is, with the increase of the port number, it will be very cumbersome to manage, so mysqld_multi comes on stage. Abandon previous practices.

1. First configure my.cnf (a lot of parameters are omitted here, the parameters of mysqld1 and mysqld2 are the same as those of mysqld before, only the modified part is released, mysqld_multi is a new addition, and the username and password are the same for both databases)
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = multi_admin
password = my_password

[mysqld1]
port = 3306
socket = /tmp/mysql.sock1
datadir = /usr/local /mysql/var
log=/usr/local/mysql/log/mysql.log innodb_data_home_dir

=/usr/local/mysql/var
innodb_log_group_home_dir=/usr/local/mysql/var

[mysqld2]
port=3307
socket=/tmp/mysql .sock2
datadir = /usr/local/mysql/var3307
log=/usr/local/mysql/log/mysql3307.log

innodb_data_home_dir = /usr/local/mysql/var3307
innodb_log_group_home_dir = /usr/local/mysql/var3307

2. Initialize the database directory (same as above)
/usr/local/mysql/scripts/mysql_install_db --datadir=/usr/local/mysql/var3307 / --user=mysql --basedir=/usr/local/mysql 

3. Start multiple instances:
/usr/local/mysql/bin/mysqld_multi start 1-2 //Start 1 and 2
/usr/local/mysql/bin /mysqld_multi start 1 //Only start 1,
you can view the port that mysql starts with netstat -anp | grep mysql.

4. Log in to mysql (same as above)
mysql -S /tmp/mysql.sock1 //sock login
to mysql -uroot -p -h127.0.0.1 -P3307 //port number login

5, stop MYSQL
/usr/local/mysql/bin /mysqld_multi stop 1-2 //stop 1 and 2
/usr/local/mysql/bin/mysqld_multi stop 1 //stop 1 only

The full text is complete.

 

More can go to: http://www.webyang.net/Html/web/article_311.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326266438&siteId=291194637