Documentation Home
MySQL 8.4 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 39.8Mb
PDF (A4) - 39.9Mb
Man Pages (TGZ) - 257.9Kb
Man Pages (Zip) - 364.9Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


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

20.1.1.1 源服务器到副本服务器复制

传统的 MySQL复制提供了一个简单的源服务器到副本服务器的复制方法。源服务器是主服务器,一或多个副本服务器是从服务器。源服务器应用事务,提交它们,然后将它们异步发送到副本服务器,以便在语句级别(语句基于复制)或行级别(行基于复制)重新执行或应用。它是一个共享 nothing 系统,其中所有服务器默认都拥有完整的数据副本。

图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.

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