Multiple instances of one machine mysqld_multi

Source: Internet
Author: User

According to the MySQL Management Manual, each MySQL service can be independent, so it calls. the different startup options in CNF are the GNR values mentioned below. Different ports are used to generate their own socket files, and the Service database is independent.
The required preparations are as follows: (they are all ready-made)
1. You only need to install a set of MySQL server software.
2. mysqld_multi
3. You need to modify/etc/My. CNF.

Explanation:
1./configure-Prefix =/usr/local/MySQL-datadir =/usr/local/MySQL/data1-sysconfdir =/etc
Note:-Prefix install MySQL to/usr/local/MySQL,
-Datadir generates/usr/local/MySQL/data1 from the database.
-Sysconfdir indicates that the search path of the my. CNF configuration file used by MySQL is/etc.
Other MySQL installation procedures are omitted.

2. mysqld_multi is a service process that manages multiple mysqld. These service processes use different UNIX sockets or listen on different ports. It can start, stop, and monitor the current service status.

3.ProgramSearch for [mysqld #] segments in my. CNF (or the custom configuration file in-config-file), and "#" can be any positive integer. This positive integer is the segment sequence mentioned below, I .e., GNR. The serial number of a segment is used as the parameter of mysqld_multi to distinguish different segments, so that you can control the startup, stop, or obtain report information of a specific mysqld process. The parameters in these groups are like starting a mysqld

The following is a part of my. CNF file.

 

[Mysqld_multi]
Mysqld =/usr/bin/mysqld_safe
Mysqladmin =/usr/bin/mysqladmin
User = mysqlmulti

Password = mysqlmulti
Log =/home/client/log/MySQL/log-multi.err
# The MySQL Server
[Mysqld1]
User = client
Port = 3307
Socket =/home/client/data/mysql_3307/mysqld. Sock
Datadir =/home/client/data/mysql_3307
PID-file =/home/client/data/mysql_3307/mysqld. PID
Log-err =/home/client/log/log-3307.err
Log =/home/client/log
# Skip-locking
Character_set_server = utf8

[Mysqld2]
User = client
Port = 3308
Socket =/home/client/data/mysql_3308/mysqld. Sock
Datadir =/home/client/data/mysql_3308
PID-file =/home/client/data/mysql_3308/mysqld. PID
Log-err =/home/client/log/log-3308.err
Log =/home/client/log
# Skip-locking
Character_set_server = utf8

Here, my configuration file contains two services, mysql1 and mysqld2, respectively using 3306 and 3307, and each datadir path is also different. Some other settings are available in my. CNF's original content.

 

 

Usage: # mysqld_multi [Options] {START | stop | report} [GNR [, GNR]…]

Start, stop, and report are the operations you want to perform. You can specify an operation on a separate service or multiple services, which is different from the GNR list after the option. If the GNR list is not specified, mysqld_multi operates on all services according to the option file.

The value of each GNR is the serial number of a group or the serial number range of a group. The value of this item must be the last number of the group name. For example, if the group name is mysqld17, the value of this item is 17. if a range is specified, use a hyphen (-) to connect two numbers. If the value of GNR is 10-13, it means that the group mysqld10 is in the group mysqld13. You can specify multiple groups or group ranges in the command line and separate them with commas. Blank characters (such as spaces or tabs) are not allowed. parameters after blank characters are ignored.

 

 

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF start 1

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF stop 1 stop

 

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF start 2

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF stop 1 stop

 

And so on.

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF start 1-N start n instances

 

You can also check whether a service is started.

Sudo/usr/bin/mysqld_multi -- config-file =/home/client/CONF/My. CNF Report 2

Reporting MySQL servers
MySQL server from group: mysqld2 is running

 

 

View startup:

# Ps aux
/Usr/bin/mysqld_safe -- user = client -- Port = 3307 -- socket =/home/client/data/mysql_3307/mysqld. sock -- datadir =/home/client/data/mysql_3307 -- PID-file =/home/client/data/mysql_3307/mysqld. PID -- log-err =/home/client/log/log-3307.err -- log =/home/client/log -- character_set_server = utf8
/Usr/bin/mysqld_safe -- user = client -- Port = 3308 -- socket =/home/client/data/mysql_3308/mysqld. sock -- datadir =/home/client/data/mysql_3308 -- PID-file =/home/client/data/mysql_3308/mysqld. PID -- log-err =/home/client/log/log-3308.err -- log =/home/client/log -- character_set_server = utf8

 

 

2. How to connect to the specified MySQL Server

Mysql-uroot-S/home/client/data/mysql_3307/mysqld. Sock

 

[Czh @ dev1 MySQL] $ mysql-uroot-S/home/client/data/mysql_3307/mysqld. Sock
Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 13
Server version: 5.0.45-log Source Distribution

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql>

 

Create users and databases

 

[Czh @ dev1 MySQL] $ mysql-uroot-p3307-h127.0.0.1
Welcome to the MySQL monitor. commands end with; or \ G.
Your MySQL connection ID is 15
Server version: 5.0.45-log Source Distribution

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql> Create Database favorite default Character Set utf8;

Mysql> grant all privileges on favorite. * to client @ **. ** identified by 'Password ';

Mysql> grant shutdonw on *. * To 'mysqlmulti 'on 'localhost' identity by 'mysqlmulti ';
Mysql> flush privileges;
Mysql> quit;

Now you can use the created user to log on.

 

Mysql-uclient-ppassword-p3307-H **.**.**.**

 
Write it here.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.