文档首页
MySQL 9.0 参考手册
相关文档 下载此手册
PDF (US Ltr) - 40.0Mb
PDF (A4) - 40.1Mb
手册页 (TGZ) - 258.2Kb
手册页 (Zip) - 365.3Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 9.0 参考手册  /  ...  /  源到副本复制

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 复制协议(及其半同步变体)的示意图。不同实例之间的箭头表示服务器之间交换的消息或服务器与客户端应用程序之间交换的消息。