MySQL主从结构实际中是用到最多的一种架构. 新上的两台服务器B和C,要替换掉之前旧的服务器A,同时,B和C是新的主从关系.因此,配置成级联复制,来迁移数据,也方便切换.

架构图如下:

master A ——> slave B ——> slave C

有这么情况发生了,服务器B可以正常复制服务器A的数据,服务器B和C主从状态Slave_IO_Running和Slave_SQL_Running都是yes的,但是服务器C却无法复制新的数据.

原因分析:

1.检查服务器B有没有开启二进制日志log_bin

2.log_slave_updates是否启用

log_slave_updates是将从服务器从主服务器收到的更新记入到从服务器自己的二进制日志文件中.

上面的问题是由于没有启用log_slave_updates=1导致的.

总结:

因此,对于mysql级联复制,上游的从服务器不仅仅要开启log_bin还要开启log_slave_updates,否则将导致下游的从服务器无法更新复制.

  •  --log-slave-updates

    Command-Line Format--log-slave-updates
    System VariableNamelog_slave_updates
    Variable ScopeGlobal
    Dynamic VariableNo
    Permitted ValuesTypeboolean
    DefaultOFF

    Normally, a slave does not log to its own binary log any updates that are received from a master server. This option tells the slave to log the updates performed by its SQL thread to its own binary log. For this option to have any effect, the slave must also be started with the --log-bin option to enable binary logging. --log-slave-updatesis used when you want to chain replication servers. For example, you might want to set up replication servers using this arrangement:

    A -> B -> C

    Here, A serves as the master for the slave B, and B serves as the master for the slave C. For this to work, B must be both a master and a slave. You must start both A and B with --log-bin to enable binary logging, and B with the --log-slave-updates option so that updates received from A are logged by B to its binary log.