CHANGE REPLICATION FILTERfilter
[,filter
] [, ...] [FOR CHANNELchannel
]filter
: { REPLICATE_DO_DB = (db_list
) | REPLICATE_IGNORE_DB = (db_list
) | REPLICATE_DO_TABLE = (tbl_list
) | REPLICATE_IGNORE_TABLE = (tbl_list
) | REPLICATE_WILD_DO_TABLE = (wild_tbl_list
) | REPLICATE_WILD_IGNORE_TABLE = (wild_tbl_list
) | REPLICATE_REWRITE_DB = (db_pair_list
) }db_list
:db_name
[,db_name
][, ...]tbl_list
:db_name.table_name
[,db_name.table_name
][, ...]wild_tbl_list
: 'db_pattern.table_pattern
'[, 'db_pattern.table_pattern
'][, ...]db_pair_list
: (db_pair
)[, (db_pair
)][, ...]db_pair
:from_db
,to_db
CHANGE REPLICATION FILTER
sets one or more replication filtering rules on the replica in the same way as starting the replica mysqld with replication filtering options such as --replicate-do-db
or --replicate-wild-ignore-table
. CHANGE REPLICATION FILTER
在副本上设置一个或多个复制筛选规则,方法与使用复制筛选选项(如--replicate-do-db
或--replicate-wild-ignore-table
)启动副本mysqld相同。Unlike the case with the server options, this statement does not require restarting the server to take effect, only that the replication SQL thread be stopped using 与服务器选项的情况不同,此语句不需要重新启动服务器才能生效,只需要先使用STOP REPLICA | SLAVE SQL_THREAD
first (and restarted with START REPLICA | SLAVE SQL_THREAD
afterwards). STOP REPLICA | SLAVE SQL_THREAD
停止复制SQL线程(然后使用START REPLICA | SLAVE SQL_THREAD
重新启动)。CHANGE REPLICATION FILTER
requires the REPLICATION_SLAVE_ADMIN
privilege (or the deprecated SUPER
privilege). CHANGE REPLICATION FILTER
需要REPLICATION_SLAVE_ADMIN
权限(或不推荐使用的SUPER
权限)。Use the 使用FOR CHANNEL
clause to make a replication filter specific to a replication channel, for example on a multi-source replica. channel
FOR CHANNEL
子句使复制筛选器特定于复制通道,例如在多源复制副本上。channel
Filters applied without a specific 未使用特定FOR CHANNEL
clause are considered global filters, meaning that they are applied to all replication channels.FOR CHANNEL
子句应用的筛选器被视为全局筛选器,这意味着它们应用于所有复制通道。
Global replication filters cannot be set 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. 无法在为组复制配置的MySQL服务器实例上设置全局复制筛选器,因为筛选某些服务器上的事务会使组无法就一致状态达成一致。Channel specific replication filters can be set on replication channels that are not directly involved with Group Replication, such as where a group member also acts as a replica to a source that is outside the group. 可以在与组复制不直接相关的复制通道上设置特定于通道的复制筛选器,例如,在组成员还充当组外源的副本的情况下。They cannot be set on the 不能在group_replication_applier
or group_replication_recovery
channels.group_replication_applier
或group_replication_recovery
通道上设置它们。
The following list shows the 以下列表显示了CHANGE REPLICATION FILTER
options and how they relate to --replicate-*
server options:CHANGE REPLICATION FILTER
(更改复制筛选器)选项及其与服务器选项--replicate-*
的关系:
REPLICATE_DO_DB
: Include updates based on database name. :包括基于数据库名称的更新。Equivalent to 相当于--replicate-do-db
.--replicate-do-db
。
REPLICATE_IGNORE_DB
: Exclude updates based on database name. :根据数据库名称排除更新。Equivalent to 相当于--replicate-ignore-db
.--replicate-ignore-db
。
REPLICATE_DO_TABLE
: Include updates based on table name. :包括基于表名的更新。Equivalent to 相当于--replicate-do-table
.--replicate-do-table
。
REPLICATE_IGNORE_TABLE
: Exclude updates based on table name. :根据表名排除更新。Equivalent to 相当于--replicate-ignore-table
.--replicate-ignore-table
。
REPLICATE_WILD_DO_TABLE
: Include updates based on wildcard pattern matching table name. :包括基于通配符模式匹配表名称的更新。Equivalent to 相当于--replicate-wild-do-table
.--replicate-wild-do-table
。
REPLICATE_WILD_IGNORE_TABLE
: Exclude updates based on wildcard pattern matching table name. :根据通配符模式匹配表名排除更新。Equivalent to 相当于--replicate-wild-ignore-table
.--replicate-wild-ignore-table
。
REPLICATE_REWRITE_DB
: Perform updates on replica after substituting new name on replica for specified database on source. :在将副本上的新名称替换为源上的指定数据库后,对副本执行更新。Equivalent to 相当于--replicate-rewrite-db
.--replicate-rewrite-db
。
The precise effects of REPLICATE_DO_DB
and REPLICATE_IGNORE_DB
filters are dependent on whether statement-based or row-based replication is in effect. REPLICATE_DO_DB
和REPLICATE_IGNORE_DB
筛选器的精确效果取决于基于语句还是基于行的复制是否有效。See Section 17.2.5, “How Servers Evaluate Replication Filtering Rules”, for more information.有关更多信息,请参阅第17.2.5节,“服务器如何评估复制筛选规则”。
Multiple replication filtering rules can be created in a single 通过使用逗号分隔规则,可以在单个CHANGE REPLICATION FILTER
statement by separating the rules with commas, as shown here:CHANGE REPLICATION FILTER
语句中创建多个复制筛选规则,如下所示:
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (d1), REPLICATE_IGNORE_DB = (d2);
Issuing the statement just shown is equivalent to starting the replica mysqld with the options 发出刚才显示的语句相当于使用选项--replicate-do-db=d1
--replicate-ignore-db=d2
.--replicate-do-db=d1
--replicate-ignore-db=d2
启动副本mysqld。
On a multi-source replica, which uses multiple replication channels to process transaction from different sources, use the 在使用多个复制通道处理来自不同源的事务的多源复制副本上,使用FOR CHANNEL
clause to set a replication filter on a replication channel:channel
FOR CHANNEL
子句在复制通道上设置复制筛选器:channel
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (d1) FOR CHANNEL channel_1;
This enables you to create a channel specific replication filter to filter out selected data from a source. 这使您能够创建特定于通道的复制筛选器,以从源中筛选出选定的数据。When a 提供FOR CHANNEL
clause is provided, the replication filter statement acts on that replication channel, removing any existing replication filter which has the same filter type as the specified replication filters, and replacing them with the specified filter. FOR CHANNEL
子句时,复制筛选器语句将作用于该复制通道,删除与指定复制筛选器具有相同筛选器类型的任何现有复制筛选器,并将其替换为指定筛选器。Filter types not explicitly listed in the statement are not modified. 不会修改语句中未明确列出的筛选器类型。If issued against a replication channel which is not configured, the statement fails with an ER_SLAVE_CONFIGURATION error. 如果针对未配置的复制通道发出,则该语句将失败,并出现ER_SLAVE_CONFIGURATION
错误。If issued against Group Replication channels, the statement fails with an ER_SLAVE_CHANNEL_OPERATION_NOT_ALLOWED error.如果针对组复制通道发出,该语句将失败,并出现ER_SLAVE_CHANNEL_OPERATION_NOT_ALLOWED
错误。
On a replica with multiple replication channels configured, issuing 在配置了多个复制通道的复制副本上,发出不带有CHANGE REPLICATION FILTER
with no FOR CHANNEL
clause configures the replication filter for every configured replication channel, and for the global replication filters. FOR CHANNEL
子句的CHANGE REPLICATION FILTER
为每个配置的复制通道和全局复制筛选器配置复制筛选器。For every filter type, if the filter type is listed in the statement, then any existing filter rules of that type are replaced by the filter rules specified in the most recently issued statement, otherwise the old value of the filter type is retained. 对于每个筛选器类型,如果该筛选器类型在语句中列出,则该类型的任何现有筛选器规则都将替换为最近发布的语句中指定的筛选器规则,否则将保留该筛选器类型的旧值。For more information see Section 17.2.5.4, “Replication Channel Based Filters”.有关更多信息,请参阅第17.2.5.4节,“基于复制通道的筛选器”。
If the same filtering rule is specified multiple times, only the last such rule is actually used. 如果多次指定同一筛选规则,则仅实际使用最后一个此类规则。For example, the two statements shown here have exactly the same effect, because the first 例如,此处显示的两条语句具有完全相同的效果,因为第一条语句中的第一条REPLICATE_DO_DB
rule in the first statement is ignored:REPLICATE_DO_DB
规则被忽略:
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db1, db2), REPLICATE_DO_DB = (db3, db4); CHANGE REPLICATION FILTER REPLICATE_DO_DB = (db3, db4);
This behavior differs from that of the 此行为不同于--replicate-*
filter options where specifying the same option multiple times causes the creation of multiple filter rules.--replicate-*
过滤器选项,在该选项中多次指定同一选项会导致创建多个过滤器规则。
Names of tables and database not containing any special characters need not be quoted. 不包含任何特殊字符的表和数据库的名称不需要引用。Values used with 与REPLICATION_WILD_TABLE
and REPLICATION_WILD_IGNORE_TABLE
are string expressions, possibly containing (special) wildcard characters, and so must be quoted. REPLICATION_WILD_TABLE
和REPLICATION_WILD_IGNORE_TABLE
一起使用的值是字符串表达式,可能包含(特殊)通配符,因此必须引用。This is shown in the following example statements:以下示例语句显示了这一点:
CHANGE REPLICATION FILTER REPLICATE_WILD_DO_TABLE = ('db1.old%'); CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('db1.new%', 'db2.new%');
Values used with 与REPLICATE_REWRITE_DB
represent pairs of database names; each such value must be enclosed in parentheses. REPLICATE_REWRITE_DB
一起使用的值表示成对的数据库名称;每个这样的值必须用括号括起来。The following statement rewrites statements occurring on database 以下语句将发生在源数据库db1
on the source to database db2
on the replica:db1
上的语句重写为副本数据库db2
上的语句:
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB = ((db1, db2));
The statement just shown contains two sets of parentheses, one enclosing the pair of database names, and the other enclosing the entire list. 刚才显示的语句包含两组括号,一组包含数据库名称对,另一组包含整个列表。This is perhaps more easily seen in the following example, which creates two 下面的示例可能更容易看出这一点,它创建了两个rewrite-db
rules, one rewriting database dbA
to dbB
, and one rewriting database dbC
to dbD
:rewrite-db
规则,一个将数据库dbA
重写为dbB
,另一个将数据库dbC
重写为dbD
:
CHANGE REPLICATION FILTER REPLICATE_REWRITE_DB = ((dbA, dbB), (dbC, dbD));
The CHANGE REPLICATION FILTER
statement replaces replication filtering rules only for the filter types and replication channels affected by the statement, and leaves other rules and channels unchanged. CHANGE REPLICATION FILTER
语句仅替换受该语句影响的筛选器类型和复制通道的复制筛选规则,而保留其他规则和通道不变。If you want to unset all filters of a given type, set the filter's value to an explicitly empty list, as shown in this example, which removes all existing 如果要取消设置给定类型的所有筛选器,请将筛选器的值设置为显式空列表,如本例所示,这将删除所有现有的REPLICATE_DO_DB
and REPLICATE_IGNORE_DB
rules:REPLICATE_DO_DB
和REPLICATE_IGNORE_DB
规则:
CHANGE REPLICATION FILTER REPLICATE_DO_DB = (), REPLICATE_IGNORE_DB = ();
Setting a filter to empty in this way removes all existing rules, does not create any new ones, and does not restore any rules set at mysqld startup using 以这种方式将筛选器设置为空会删除所有现有规则,不会创建任何新规则,也不会使用命令行或配置文件中的--replicate-*
options on the command line or in the configuration file.--replicate-*
选项还原mysqld启动时设置的任何规则。
The RESET REPLICA | SLAVE ALL
statement removes channel specific replication filters that were set on channels deleted by the statement. RESET REPLICA | SLAVE ALL
语句删除在该语句删除的通道上设置的特定于通道的复制筛选器。When the deleted channel or channels are recreated, any global replication filters specified for the replica are copied to them, and no channel specific replication filters are applied.当重新创建已删除的一个或多个通道时,为复制副本指定的任何全局复制筛选器都将复制到它们,并且不会应用任何特定于通道的复制筛选器。
For more information, see Section 17.2.5, “How Servers Evaluate Replication Filtering Rules”.有关更多信息,请参阅第17.2.5节,“服务器如何评估复制筛选规则”。