文档主页
MySQL 8.4 参考手册
相关文档 下载本手册
PDF (US Ltr) - 39.9Mb
PDF (A4) - 40.0Mb
手册页 (TGZ) - 258.5Kb
手册页 (Zip) - 365.5Kb
信息 (Gzip) - 4.0Mb
信息 (Zip) - 4.0Mb


MySQL 8.4 参考手册  /  ...  /  从源到副本的复制

20.1.1.1 从源到副本的复制

传统的 MySQL 复制 提供了一种简单的从源到副本的复制方法。源是主节点,并且有一个或多个副本,它们是从节点。源应用事务,提交它们,然后它们稍后(因此异步)发送到副本以重新执行(在基于语句的复制中)或应用(在基于行的复制中)。它是一个无共享系统,默认情况下所有服务器都拥有数据的完整副本。

图 20.1 MySQL 异步复制

A transaction received by the source is executed, written to the binary log, then committed, and a response is sent to the client application. The record from the binary log is sent to the relay logs on Replica 1 and Replica 2 before the commit takes place on the source. On each of the replicas, the transaction is applied, written to the replica's binary log, and committed. The commit on the source and the commits on the replicas are all independent and asynchronous.

还有半同步复制,它为协议添加了一个同步步骤。这意味着主节点在应用时等待从节点确认它已收到事务。只有这样,主节点才会恢复提交操作。

图 20.2 MySQL 半同步复制

A transaction received by the source is executed and written to the binary log. The record from the binary log is sent to the relay logs on Replica 1 and Replica 2. The source then waits for an acknowledgement from the replicas. When both of the replicas have returned the acknowledgement, the source commits the transaction, and a response is sent to the client application. After each replica has returned its acknowledgement, it applies the transaction, writes it to the binary log, and commits it. The commit on the source depends on the acknowledgement from the replicas, but the commits on the replicas are independent from each other and from the commit on the source.

在两张图中,有一张是经典的异步 MySQL 复制协议(及其半同步变体)的示意图。不同实例之间的箭头表示服务器之间交换的消息或服务器与客户端应用程序之间交换的消息。