master my.cnf部份配置:

log-bin                = /data/mysqllog/binlog/mysql-binlog_slave_updates    #让slave 也可以充当master角色,写binlogreplicate-do-db = dingmh       #需要复制的库server-id              = 20   #服务器的ID,主从不能相同,binlog-do-db            = dingmh    binlog-ignore-db        = mysqlbinlog-ignore-db        = dashboard_productionbinlog-ignore-db        = testbinlog-ignore-db        = performance_schemaauto_increment_increment=2  auto_increment_offset=2

slave my.cnf部份配置:

log-bin                = /data/mysqllog/binlog/mysql-binlog_slave_updatesserver-id              = 21replicate-do-db = dingmhbinlog-do-db            = dingmhbinlog-ignore-db        = mysqlbinlog-ignore-db        = dashboard_productionbinlog-ignore-db        = testbinlog-ignore-db        = performance_schemaauto_increment_increment=2auto_increment_offset=1

主从同步是靠binlog日志来做同步的,binlog里记录着server-id,如果读到与自己相同的server-id

就不会执行操作,如果主从中断想重新同步,需要修改server-id