#### 18.1.1.1 源到副本复制

[](<>)[](<>)

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

[](<>)

**图 18.1 MySQL 异步复制**

<img alt="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." src="images/async-replication-diagram.png" height="304" width="725" />

还有半同步复制，它在协议中增加了一个同步步骤。这意味着主节点在申请时等待辅助节点确认它已*已收到*交易。只有这样，主节点才会恢复提交操作。

[](<>)

**图 18.2 MySQL 半同步复制**

<img alt="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." src="images/semisync-replication-diagram.png" height="396" width="725" />

在两张图片中，有一个经典的异步 MySQL 复制协议（以及它的半同步变体）的图表。不同实例之间的箭头表示服务器之间交换的消息或服务器与客户端应用程序之间交换的消息。
