This experiment will use MySQL 5.6.x as a multi-"master".
0 test Environment:
OS: CentOS 6.5
master_1: 192.168.1.185 (MySQL 5.6.30)
master_2: 192.168.1.186 (MySQL 5.6.30)
slave: 192.168.1.1.187 (MySQL 5.7.15)
0 Configuration:
Master_1 Related configurations:
- [Mysqld]
- server_id = 185
- Log-bin = master_1
- Log-bin-index = Master_1.index
Master_2 Related configurations:
- [Mysqld]
- server_id = 186
- Log-bin = master_2
- Log-bin-index = Master_2.index
Slave related configurations:
- [Mysqld]
- server_id = 187
- Relay-log = Slave
- Relay-log-index = Slave.index
- # slave in a multi-source replication structure, the official requirements for Master-info and relay-log-info repositories must be table.
- # If it is file, it will fail when multiple master is added: Er_slave_new_channel_wrong_repository.
- Master-info-repository = TABLE
- Relay-log-info-repository = TABLE
0 Create a replication user on master_1 & master_2:
- GRANT REPLICATION SLAVE On * * to [e-mail protected] ' 192.168.1.187 ' identified by ' repl ';
- FLUSH privileges;
0 Test Data Preparation:
master_1 test Data:
- Master_1> FLUSH LOGS;
- Query OK, 0 rows Affected (0.00 sec)
- master_1> SHOW BINARY LOGS; --Remember the name and position of the current Binlog
- +-----------------+-----------+
- | Log_name | File_size |
- +-----------------+-----------+
- | master_1.000001 | 166 |
- | master_1.000002 | 455 |
- | master_1.000003 | 120 |
- +-----------------+-----------+
- 3 Rows in Set (0.00 sec)
- master_1> CREATE DATABASE master_1;
- Query OK, 1 row affected (0.03 sec)
Master_2 test Data:
- Master_2> FLUSH LOGS;
- Query OK, 0 rows Affected (0.00 sec)
- master_2> SHOW BINARY LOGS; --Remember the name and position of the current Binlog
- +-----------------+-----------+
- | Log_name | File_size |
- +-----------------+-----------+
- | master_2.000001 | 166 |
- | master_2.000002 | 455 |
- | master_2.000003 | 120 |
- +-----------------+-----------+
- 3 Rows in Set (0.00 sec)
- master_2> CREATE DATABASE master_2;
- Query OK, 1 row affected (0.02 sec)
0 performed on Slave:
- Salve> Change MASTER to
- Master_host= ' 192.168.1.185 ',
- Master_user= ' Repl ',
- master_port=3306,
- Master_password= ' Repl ',
- Master_log_file= ' master_1.000003 ',
- master_log_pos=120
- For CHANNEL ' master_1 ';
- Query OK, 0 rows affected, 2 warnings (0.02 sec)-The warnings generated here are some security recommendations and warnings that this experiment ignores.
- Salve> Change MASTER to
- Master_host= ' 192.168.1.186 ',
- Master_user= ' Repl ',
- master_port=3306,
- Master_password= ' Repl ',
- Master_log_file= ' master_2.000003 ',
- master_log_pos=120
- For CHANNEL ' master_2 ';
- Query OK, 0 rows affected, 2 warnings (0.02 sec)
- slave> START Slave;
- Query OK, 0 rows affected (0.01 sec)
- Salve> SHOW DATABASES; -The Binlog events on master_1 and master_2 have been properly apply.
- +--------------------+
- | Database |
- +--------------------+
- | Information_schema |
- | master_1 |
- | master_2 |
- | MySQL |
- | Performance_schema |
- | SYS |
- +--------------------+
- 6 rows in Set (0.00 sec)
Finally, the replication status can be found through the start slave status
- slave> SHOW Slave Status\g
- 1. Row ***************************
- Slave_io_state:waiting for Master to send event
- master_host:192.168.1.185
- Master_user:repl
- master_port:3306
- ............................................................
- Slave_io_running:yes
- Slave_sql_running:yes
- ............................................................
- master_server_id:185
- Master_uuid:ee1f8704-58c4-11e6-95b5-000c297f23b7
- Master_Info_File:mysql.slave_master_info
- sql_delay:0
- Sql_remaining_delay:null
- Slave_sql_running_state:slave have read all relay log; Waiting for more updates
- ............................................................
- Channel_name:master_1
- Master_tls_version:
- 2. Row ***************************
- Slave_io_state:waiting for Master to send event
- master_host:192.168.1.186
- Master_user:repl
- master_port:3306
- Connect_retry:60
- ............................................................
- Slave_io_running:yes
- Slave_sql_running:yes
- ............................................................
- master_server_id:186
- master_uuid:53774f2d-7e14-11e6-8900-000c298e914c
- Master_Info_File:mysql.slave_master_info
- sql_delay:0
- Sql_remaining_delay:null
- Slave_sql_running_state:slave have read all relay log; Waiting for more updates
- ............................................................
- Channel_name:master_2
- Master_tls_version:
- 2 rows in Set (0.00 sec)
0 Test:
Operation on master_1:
- Master_1> CREATE TABLE master_1.test_table (id int);
- Query OK, 0 rows affected (0.05 sec)
- Master_1> INSERT into master_1.test_table SELECT 666666;
- Query OK, 1 row affected (0.01 sec)
- Records:1 duplicates:0 warnings:0
Operation on master_2:
- Master_2> CREATE TABLE master_2.test_table (massage varchar (16));
- Query OK, 0 rows affected (0.02 sec)
- Master_2> INSERT into master_2.test_table SELECT ' hehe hey ';
- Query OK, 1 row Affected (0.00 sec)
- Records:1 duplicates:0 warnings:0
- Master_2> INSERT into master_2.test_table SELECT ' samyang inflammation ';
- Query OK, 1 row Affected (0.00 sec)
- Records:1 duplicates:0 warnings:0
Operation on Slave:
- salve> SELECT ID from master_1.test_table;
- +--------+
- | ID |
- +--------+
- | 666666 |
- +--------+
- 1 row in Set (0.00 sec)
- salve> SELECT massage from master_2.test_table;
- +--------------+
- | Massage |
- +--------------+
- | Hey heh |
- | Samyang of the disease |
- +--------------+
- 2 rows in Set (0.00 sec)
0 Other related syntax:
- Start/stop/reset all/reset SLAVE for CHANNEL ' XXX ';
- SHOW SLAVE STATUS for CHANNEL ' XXX ';
Ps.
Similar to the traditional position method described above, the Gtid mode is similarly configured, after opening the Gtid, you need to pay attention to using the for CHANNEL ' xxx ' keyword, such as:
- Change MASTER to
- Master_host= ',
- Master_user= ' Repl ',
- master_port=3306,
- Master_password= ' Repl ',
- Master_auto_position = 1
- For CHANNEL ' master_1 ';
Multiple hosts of the schema name can not be the same, (for example, master_1 for db_00 ... db_09 total 10 libraries, master_2 for db_10 ... db_19,master_3 ... db_20 ... )
mysql5.6-"5.7