本节描述基于二进制日志文件位置方法的 MySQL 服务器之间的复制,其中作为源的 MySQL 实例(数据库更改发生的地方)将更新和更改写入二进制日志,作为“事件”。二进制日志中的信息根据记录的数据库更改以不同的日志格式存储。副本配置为从源读取二进制日志,并在副本的本地数据库上执行二进制日志中的事件。This section describes replication between MySQL servers based on the binary log file position method, where the MySQL instance operating as the source (where the database changes take place) writes updates and changes as “events” to the binary log. The information in the binary log is stored in different logging formats according to the database changes being recorded. Replicas are configured to read the binary log from the source and to execute the events in the binary log on the replica's local database.
每个副本都会接收到二进制日志的全部内容副本。副本有责任决定二进制日志中哪些语句应被执行。除非另行指定,否则源的二进制日志中的所有事件都会在副本上执行。如有需要,您可以配置副本仅处理适用于特定数据库或表的事件。Each replica receives a copy of the entire contents of the binary log. It is the responsibility of the replica to decide which statements in the binary log should be executed. Unless you specify otherwise, all events in the source's binary log are executed on the replica. If required, you can configure the replica to process only events that apply to particular databases or tables.
您无法配置源仅记录某些事件。You cannot configure the source to log only certain events.
每个副本都会保留二进制日志坐标的记录:它已从源读取和处理的文件名及文件内位置。这意味着多个副本可以连接到源并执行同一二进制日志的不同部分。由于副本控制此过程,单个副本可以连接和断开服务器而不会影响源的操作。此外,由于每个副本都会记录二进制日志的当前位置,因此副本可以断开连接,然后重新连接并继续处理。Each replica keeps a record of the binary log coordinates: the file name and position within the file that it has read and processed from the source. This means that multiple replicas can be connected to the source and executing different parts of the same binary log. Because the replicas control this process, individual replicas can be connected and disconnected from the server without affecting the source's operation. Also, because each replica records the current position within the binary log, it is possible for replicas to be disconnected, reconnect and then resume processing.
源服务器和每个副本必须配置唯一的 ID(使用 server_id 系统变量)。此外,每个副本必须配置有关源服务器主机名、日志文件名以及文件中的位置的信息。这些详细信息可以在 MySQL 会话中通过副本上的 CHANGE
REPLICATION SOURCE TO 语句进行控制。详细信息存储在副本的连接元数据存储库中(参见 第 19.2.4 节,“中继日志和复制元数据存储库”)。The source and each replica must be configured with a unique ID
(using the server_id system
variable). In addition, each replica must be configured with
information about the source's host name, log file name, and
position within that file. These details can be controlled from
within a MySQL session using a CHANGE
REPLICATION SOURCE TO statement on the replica. The
details are stored within the replica's connection metadata
repository (see Section 19.2.4, “Relay Log and Replication Metadata Repositories”).