master my.cnf部份配置:




log-bin                = /data/mysqllog/binlog/mysql-bin
log_slave_updates    #让slave 也可以充当master角色,写binlog
replicate-do-db = dingmh       #需要复制的库
server-id              = 20   #服务器的ID,主从不能相同,
binlog-do-db            = dingmh    
binlog-ignore-db        = mysql
binlog-ignore-db        = dashboard_production
binlog-ignore-db        = test
binlog-ignore-db        = performance_schema
auto_increment_increment=2  
auto_increment_offset=2

slave my.cnf部份配置:



log-bin                = /data/mysqllog/binlog/mysql-bin
log_slave_updates
server-id              = 21
replicate-do-db = dingmh
binlog-do-db            = dingmh
binlog-ignore-db        = mysql
binlog-ignore-db        = dashboard_production
binlog-ignore-db        = test
binlog-ignore-db        = performance_schema
auto_increment_increment=2
auto_increment_offset=1



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

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