1.1Multi-instance explanation1.1.1Create an environment configuration file
3306 3307 3308
multiple mysqld processes (mysqld_safe)
Multiple configuration files (port,server_id datadir log-error log-bin socket)
Managing multiple sets of data (multiple data catalogs, initializing data separately)
1.1.2Create a directory
Create mkdir-p/data/{3306,3307,3308}
Multi-instance:
3306 3307 3308
Multiple mysqld processes (Mysqld_safe)
Multiple configuration files (port server_id datadir log-error log-bin socket)
Managing multiple sets of data (multiple data catalogs, initializing data separately)
mkdir-p {3306,3307,3308}
1.1.3Creating a configuration file
Vim/data/3306/my.cnf
[Mysqld]
Basedir=/application/mysql
Datadir=/data/3306/data
server-id=3306
port=3306
Log-bin=/data/3306/mysql-bin
Socket=/data/3306/mysql.sock
Log-error=/data/3306/mysql.log
Vim/data/3307/my.cnf
[Mysqld]
Basedir=/application/mysql
Datadir=/data/3307/data
server-id=3307
port=3307
Log-bin=/data/3307/mysql-bin
Socket=/data/3307/mysql.sock
Log-error=/data/3307/mysql.log
Vim/data/3308/my.cnf
[Mysqld]
Basedir=/application/mysql
Datadir=/data/3308/data
server-id=3308
port=3308
Log-bin=/data/3308/mysql-bin
Socket=/data/3308/mysql.sock
Log-error=/data/3308/mysql.log
1.1.4Directory Authorization
chown-r mysql.mysql/data/
1.1.5Initializing Data
Cd/application/mysql/scripts
./mysql_install_db--defaults-file=/data/3306/my.cnf--basedir=/application/mysql--datadir=/data/3306/data--user =mysql
./mysql_install_db--defaults-file=/data/3307/my.cnf--basedir=/application/mysql--datadir=/data/3307/data--user =mysql
./mysql_install_db--defaults-file=/data/3308/my.cnf--basedir=/application/mysql--datadir=/data/3308/data--user =mysql
1.1.6Start the service
/application/mysql/bin/mysqld_safe--DEFAULTS-FILE=/DATA/3306/MY.CNF &
/application/mysql/bin/mysqld_safe--DEFAULTS-FILE=/DATA/3307/MY.CNF &
/application/mysql/bin/mysqld_safe--DEFAULTS-FILE=/DATA/3308/MY.CNF &
1.1.7See if it starts
[[email protected]/data/3307/data] $netstat-lnp|grep 330
TCP 0 0::: 3306:::* LISTEN 3877/mysqld
TCP 0 0::: 3307:::* LISTEN 4048/mysqld
TCP 0 0::: 3308:::* LISTEN 4219/mysqld
UNIX 2 [ACC] STREAM LISTENING 18009 3877/mysqld/data/3306/mysql.sock
UNIX 2 [ACC] STREAM LISTENING 18137 4048/mysqld/data/3307/mysql.sock
UNIX 2 [ACC] STREAM LISTENING 18265 4219/mysqld/data/3308/mysql.sock
1.1.8Login Multiple Instances
Note: Login can enter the following command or
[Email protected] ~]$mysql-s/data/3306/mysql.sock
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2
Server Version:5.6.36-log Source Distribution
Copyright (c), Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Test |
+--------------------+
4 rows in Set (0.18 sec)
Description: The following commands can also be manipulated:
Mysql-uroot-p-p3308
Mysql-uroot-p-s/tmp/mysql3307.sock
1.1.9Multi-instance shutdown method
Note: Specify a closed port when multiple instances are closed.
[Email protected]/]$mysqladmin shutdown-s/data/3306/mysql.sock
[[email protected]/] $ps-ef|grep 330
Root 1330 1 0 08:49? 00:00:00/usr/sbin/acpid
Root 2520 2088 0 22:25 pts/1 00:00:00/bin/sh/application/mysql/bin/mysqld_safe--defaults-file=/data/3307/my . cnf
MySQL 2815 2520 0 22:25 pts/1 00:00:12/application/mysql/bin/mysqld--defaults-file=/data/3307/my.cnf--basedi R=/application/mysql--datadir=/data/3307/data--plugin-dir=/application/mysql/lib/plugin--user=mysql--log-error =/data/3307/mysql.log--pid-file=/data/3307/data/db02.pid--socket=/data/3307/mysql.sock--port=3307
Root 2879 2088 0 22:25 pts/1 00:00:00/bin/sh/application/mysql/bin/mysqld_safe--defaults-file=/data/3308/my . cnf
MySQL 3028 2879 0 22:25 pts/1 00:00:10/application/mysql/bin/mysqld--defaults-file=/data/3308/my.cnf--basedi R=/application/mysql--datadir=/data/3308/data--plugin-dir=/application/mysql/lib/plugin--user=mysql--log-error =/data/3308/mysql.log--pid-file=/data/3308/data/db02.pid--socket=/data/3308/mysql.sock--port=3308
Root 3288 3146 0 23:14 pts/2 00:00:00 grep 330
Note: The following command
Close MySQL Database
# Mysqld_multi Stop 3306
# Mysqld_multi Stop 3307,3308,3309
# Ps-ef | grep mysqld
Root 30822 12043 0 23:04 pts/0 00:00:00 grep mysqld
MySQL Multi-instance