1th Chapter MySQLMulti-instance configuration: 1.1What isMysqlMulti-instance?
To put it simply , MySQL multi-instance is running multiple mysql servers simultaneously on a single server with multiple different service ports (for example : 3306/3307/3308) , These service processes use different sockets to listen to different service ports to provide services
these MySQL multi-instance shared a set of MySQL installers , using different my.cnf configuration Files , startup programs , and data files , In the provision of services , multi-instance Mysql is logically independent , they are based on the configuration file corresponding to the set value , to obtain the corresponding resources of the server
1.2Multi-instance configuration ideas:
1. Multiple sets of independent directories
2. Each instance has independent data ( initialization data )
3. Multiple ports
4. multiple sockets
5. multiple startup programs
6. multiple log files
1.3Multi-instance configuration process: 1.3.1Create a stand-alone directory:
Mkdir-p/data/{3307,3308}chown–r Mysql.mysql/data
1.3.2Write a configuration file for each instance:
[Email protected] ~]# cat/data/3307/my.cnf[mysqld]basedir=/application/mysqldatadir=/data/3307socket=/data/3307/ Mysql.socklog-error=/data/3307/mysql.loglog_bin=/data/3307/mysql-binbinlog_format=rowskip_name_resolve=1server _id=3307port=3307
1.3.3Initializing Data:
./mysql_install_db--defaults-file=/data/3307/my.cnf--basedir=/application/mysql--datadir=/data/3307--user= Mysql
1.3.4Launch Instance:
SH mysqld_safe--defaults-file=/data/3307/my.cnf--pid-file=/data/3307/3307.pid &
Shell script Management Multi-instance service:
#!/bin/bash. /etc/init.d/functions. /etc/profilestart= '/application/mysql/bin/mysqld_safe -- Defaults-file=/data/3307/my.cnf --pid-file=/data/3307/3307.pid ' stop= ' mysqladmin -uroot -s /data/3307/mysql.sock shutdown ' port= ' ss -tunlp|grep 3307|wc -l ' Function START () { if [ $Port -ne 1 ];then $Start >/dev/null 2>&1 & sleep 3 if [ $? -eq 0 ];then action ' mysql 3307 Starting ' /bin/true fi else action ' MySQL 3307 already exists ' /bin/true fi}function stop () { if [ $Port -ne 0 ];then $Stop if [ $? -eq 0 ];then action ' Mysql stoping successfuly ' /bin/true fi else action ' mysql already stoped ' /bin/ True fi}function restart () { stop sleep 1 start}case $1 instart) START ;; Stop) STOP ;; Restart) RESTART ;; *) echo "Usage: $0 {start|stop|restart}" ;; Esac
MySQL Multi-instance configuration