MySQL5.7的多源复制

环境

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';

链接:https://www.jianshu.com/p/852946afa1ff

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

友情链接更多精彩内容