Documentation Home
MySQL 8.3 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 40.8Mb
PDF (A4) - 40.9Mb
Man Pages (TGZ) - 294.0Kb
Man Pages (Zip) - 409.0Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb
Excerpts from this Manual

MySQL 8.3 Reference Manual  /  ...  /  Source to Replica Replication

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