1. 程式人生 > >mysql的多源複製

mysql的多源複製

mysql 5.7 的multi-source replication
mysql複製分為基於binlog位置的複製和基於gtid的複製
預設mysql會建立一個名為 ‘’ 的channel
當開啟multi-source replication的時候,在slave端需要進行以下設定:

SET GLOBAL master_info_repository = ‘TABLE’;
SET GLOBAL relay_log_info_repository = ‘TABLE’;

在配置複製時,需要增加channel資訊:
CHANGE MASTER TO MASTER_HOST=‘master1’, MASTER_USER=‘rpl’, MASTER_PORT=3306, MASTER_PASSWORD=‘psww’,
MASTER_AUTO_POSITION = 1 FOR CHANNEL ‘master1’;
或者:
CHANGE MASTER TO MASTER_HOST=‘master2’, MASTER_USER=‘rpl’, MASTER_PORT=3306, MASTER_PASSWORD=‘psww’ ,
MASTER_LOG_FILE=‘binlog.000001’, MASTER_LOG_POS=628 FOR CHANNEL ‘master2’;

操作:
start slave;(啟動所有slave)
start slave for channel master1;
start slave for channel master2;

start slave io_thread; (啟動所有slave的io_thread)
start slave io_thread for channel master1;
start slave sql_thread; (啟動所有slave的sql_thread)
start slave sql_thread for channel master2;

show slave status;
show slave status for channel master1;