- 19.2.5.1 数据库级复制和二进制日志选项的评估19.2.5.1 Evaluation of Database-Level Replication and Binary Logging Options
- 19.2.5.2 表级复制选项的评估19.2.5.2 Evaluation of Table-Level Replication Options
- 19.2.5.3 复制过滤选项之间的相互作用19.2.5.3 Interactions Between Replication Filtering Options
- 19.2.5.4 基于复制通道的过滤器19.2.5.4 Replication Channel Based Filters
如果复制源服务器没有将语句写入其二进制日志,则该语句不会被复制。如果服务器确实记录了语句,该语句将发送到所有副本,每个副本会决定是否执行或忽略它。If a replication source server does not write a statement to its binary log, the statement is not replicated. If the server does log the statement, the statement is sent to all replicas and each replica determines whether to execute it or ignore it.
在源端,您可以使用 --binlog-do-db 和 --binlog-ignore-db 选项来控制二进制日志,从而控制记录哪些数据库的更改。有关服务器在评估这些选项时使用的规则的说明,请参阅 第 19.2.5.1 节,“数据库级复制与二进制日志选项的评估”。您不应使用这些选项来控制要复制的数据库和表。相反,应在从端使用过滤来控制在从端执行的事件。On the source, you can control which databases to log changes for
by using the --binlog-do-db and
--binlog-ignore-db options to
control binary logging. For a description of the rules that
servers use in evaluating these options, see
Section 19.2.5.1, “Evaluation of Database-Level Replication and Binary Logging Options”. You should not use
these options to control which databases and tables are
replicated. Instead, use filtering on the replica to control the
events that are executed on the replica.
在副本端,是否执行或忽略从源端接收到的语句的决定,是根据副本启动时使用的 --replicate-* 选项来做的。(参见 第 19.1.6 节,“复制与二进制日志选项及变量”。)由这些选项控制的过滤器也可以使用 CHANGE REPLICATION FILTER 语句动态设置。无论是在启动时使用 --replicate-* 选项创建,还是在副本服务器运行时通过 CHANGE REPLICATION
FILTER 创建,这些过滤器的规则都是相同的。请注意,在配置为组复制的 MySQL 服务器实例上,不能将复制过滤器用于组复制特定的通道,因为筛选某些服务器上的事务会导致组无法就一致状态达成共识。On the replica side, decisions about whether to execute or ignore
statements received from the source are made according to the
--replicate-* options that the replica was
started with. (See Section 19.1.6, “Replication and Binary Logging Options and Variables”.) The
filters governed by these options can also be set dynamically
using the CHANGE REPLICATION FILTER statement.
The rules governing such filters are the same whether they are
created on startup using --replicate-* options or
while the replica server is running by CHANGE REPLICATION
FILTER. Note that replication filters cannot be used on
Group Replication-specific channels on a MySQL server instance
that is configured for Group Replication, because filtering
transactions on some servers would make the group unable to reach
agreement on a consistent state.
在最简单的情况下,当没有 --replicate-* 选项时,副本会执行它从源接收到的所有语句。否则,结果取决于所给的具体选项。In the simplest case, when there are no
--replicate-* options, the replica executes all
statements that it receives from the source. Otherwise, the result
depends on the particular options given.
首先检查数据库级别的选项(--replicate-do-db,--replicate-ignore-db);有关该过程的描述,请参见第 19.2.5.1 节,“数据库级复制和二进制日志选项的评估”。如果未使用数据库级选项,则会继续检查可能使用的任何表级选项(有关讨论,请参见第 19.2.5.2 节,“表级复制选项的评估”)。如果使用了一个或多个数据库级选项但没有匹配,则该语句不会被复制。Database-level options
(--replicate-do-db,
--replicate-ignore-db) are checked
first; see Section 19.2.5.1, “Evaluation of Database-Level Replication and Binary Logging Options”, for a
description of this process. If no database-level options are
used, option checking proceeds to any table-level options that may
be in use (see Section 19.2.5.2, “Evaluation of Table-Level Replication Options”,
for a discussion of these). If one or more database-level options
are used but none are matched, the statement is not replicated.
对于仅影响数据库的语句(即 CREATE DATABASE、DROP DATABASE 和 ALTER DATABASE),数据库级选项始终优先于任何 --replicate-wild-do-table 选项。换句话说,对于此类语句,仅当没有适用的数据库级选项时,才会检查 --replicate-wild-do-table 选项。For statements affecting databases only (that is,
CREATE DATABASE,
DROP DATABASE, and
ALTER DATABASE), database-level
options always take precedence over any
--replicate-wild-do-table options.
In other words, for such statements,
--replicate-wild-do-table options
are checked if and only if there are no database-level options
that apply.
为了更容易确定给定选项集的效果,建议避免混合使用 do-* 和 ignore-* 选项,或将包含通配符的选项与不包含通配符的选项混合使用。To make it easier to determine what effect a given set of options
has, it is recommended that you avoid mixing do-*
and ignore-* options, or options containing
wildcards with options which do not.
如果指定了任何 --replicate-rewrite-db 选项,它们会在测试 --replicate-* 过滤规则之前应用。If any --replicate-rewrite-db
options were specified, they are applied before the
--replicate-* filtering rules are tested.
所有复制过滤选项遵循与 MySQL 服务器中数据库和表名适用的大小写敏感规则相同的规则,包括 lower_case_table_names 系统变量的影响。All replication filtering options follow the same rules for case
sensitivity that apply to names of databases and tables
elsewhere in the MySQL server, including the effects of the
lower_case_table_names system
variable.
在执行任何权限检查之前,会先应用过滤规则;如果某个事务被过滤掉,则不会对该事务执行权限检查,因此该事务也无法引发错误。更多信息请参见第 19.5.1.29 节,“复制期间的副本错误”。Filtering rules are applied before performing any privilege checks; if a transaction is filtered out, no privilege check is performed for that transaction, and thus no error can be raised by it. See Section 19.5.1.29, “Replica Errors During Replication”, for more information.