环境
Mysql: 5.7.18
Master1: 192.168.1.41
Master2: 192.168.1.42
Slave: 192.168.1.43
复制模式: gtid
配置文件
Master1
server_id = 41
log-bin = mysql-bin
binlog_format = row
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 30
gtid-mode = on
enforce-gtid-consistency = 1
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 2
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
Master2
server_id = 40
log-bin = mysql-bin
binlog_format = row
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 30
gtid-mode = on
enforce-gtid-consistency = 1
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 2
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
Slave
server_id = 43
log-bin = mysql-bin
binlog_format = row
binlog_cache_size = 4M
max_binlog_cache_size = 8M
max_binlog_size = 1G
expire_logs_days = 30
log-slave-updates = 1
gtid-mode = on
enforce-gtid-consistency = 1
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1
slave-parallel-workers = 4
binlog-checksum = CRC32
master-verify-checksum = 1
slave-sql-verify-checksum = 1
binlog-rows-query-log_events = 1
relay_log_recovery=1
Master1和Master2 各执行授权
mysql > grant replication slave on *.* to slave@'192.168.1.43' identified by 'xxyy';
mysql > flush privileges;
Slave 多源连接
mysql > change master to master_host='192.168.1.40',master_port=3306,master_user='slave',master_password='xxyy',master_auto_position=1 for channel 'master41';
mysql > change master to master_host='192.168.1.42',master_port=3307,master_user='slave',master_password='xxyy',master_auto_position=1 for channel 'master42';
多源复制出错处理
binlog+position
stop slave sql_thread for channel 'master41';
set global sql_slave_skip_counter=1;
start slave sql_tread for channel 'master41';
GTID
stop slave sql thread for channel 'master41';
set gtid_next='uuid:N';
begin;commit;
set gtid_next='automatic';
start slave sql_tread for channel 'master41';