复制是基于源服务器跟踪其数据库的所有更改(更新、删除等),并记录在其二进制日志中。二进制日志作为对所有修改数据库结构或内容(数据)事件的书面记录,从服务器启动时开始。通常,SELECT 语句不会被记录,因为它们既不修改数据库结构,也不修改内容。Replication is based on the source server keeping track of all
changes to its databases (updates, deletes, and so on) in its binary
log. The binary log serves as a written record of all events that
modify database structure or content (data) from the moment the
server was started. Typically, SELECT
statements are not recorded because they modify neither database
structure nor content.
每个连接到源的副本都会请求一份二进制日志的副本。也就是说,它是从源拉取数据,而不是由源将数据推送到副本。副本还会执行它收到的二进制日志中的事件。这会产生重复原始更改的效果,就像它们在源上被执行一样。表会被创建或其结构被修改,数据会根据最初在源上进行的更改进行插入、删除和更新。Each replica that connects to the source requests a copy of the binary log. That is, it pulls the data from the source, rather than the source pushing the data to the replica. The replica also executes the events from the binary log that it receives. This has the effect of repeating the original changes just as they were made on the source. Tables are created or their structure modified, and data is inserted, deleted, and updated according to the changes that were originally made on the source.
因为每个副本都是独立的,所以源的二进制日志中的更改在与源连接的每个副本上都是独立重放的。此外,由于每个副本仅通过从源请求来接收二进制日志的副本,副本可以以自己的节奏读取和更新数据库的副本,并且可以随意启动和停止复制过程,而不会影响源或副本端更新到最新数据库状态的能力。Because each replica is independent, the replaying of the changes from the source's binary log occurs independently on each replica that is connected to the source. In addition, because each replica receives a copy of the binary log only by requesting it from the source, the replica is able to read and update the copy of the database at its own pace and can start and stop the replication process at will without affecting the ability to update to the latest database status on either the source or replica side.
有关复制实现具体细节的更多信息,请参见第 19.2.3 节,“复制线程”。For more information on the specifics of the replication implementation, see Section 19.2.3, “Replication Threads”.
源服务器和副本会定期报告它们在复制过程中的状态,以便您可以监控它们。有关所有与复制相关状态的描述,请参见第 10.14 节,“检查服务器线程(进程)信息”。Source servers and replicas report their status in respect of the replication process regularly so that you can monitor them. See Section 10.14, “Examining Server Thread (Process) Information”, for descriptions of all replicated-related states.
源的二进制日志在被处理之前会写入副本上的本地中继日志。副本还记录关于当前源二进制日志位置和本地中继日志的信息。请参见第 19.2.4 节,“中继日志和复制元数据存储”。The source's binary log is written to a local relay log on the replica before it is processed. The replica also records information about the current position with the source's binary log and the local relay log. See Section 19.2.4, “Relay Log and Replication Metadata Repositories”.
数据库更改在副本上根据一套规则进行筛选,这些规则根据控制事件评估的各种配置选项和变量来应用。有关这些规则的应用详情,请参见 第 19.2.5 节,“服务器如何评估复制过滤规则”。Database changes are filtered on the replica according to a set of rules that are applied according to the various configuration options and variables that control event evaluation. For details on how these rules are applied, see Section 19.2.5, “How Servers Evaluate Replication Filtering Rules”.