# DM 的使用 - Binlog event filter

__*DM 使用*__
__*Binlog event filter*__

```
filters:  
 filter-rule-1:
    schema-pattern: "test_*"
    table-pattern: "t_*" 
    events: ["truncate table", "drop table"]   
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore                             
 filter-rule-2:
    schema-pattern: "test"
    events: ["all dml"]
    action: Do
```
-------------------------------------------------------------
Binlog event filter 是比迁移表黑白名单更加细粒度的过滤规则,可以指定只迁移或者过滤掉某些 schema / table 的指定类型 binlog,比如 INSERT、TRUNCATE TABLE。

注意
同一个表匹配上多个规则,将会顺序应用这些规则,并且黑名单的优先级高于白名单,即如果同时存在规则 Ignore 和 Do 应用在某个 table 上,那么 Ignore 生效。
从 DM v2.0.2 开始,Binlog event filter 也可以在上游数据库配置文件中进行配置。见上游数据库配置文件介绍。

参数解释
schema-pattern/table-pattern:对匹配上的上游 MySQL/MariaDB 实例的表的 binlog events 或者 DDL SQL 语句通过以下规则进行过滤。
events:binlog events 数组,仅支持从以下 Event 中选择一项或多项。

过滤 TiDB 不支持的 SQL 语句
可设置如下规则过滤 TiDB 不支持的 PROCEDURE 语句:
filters:
  filter-procedure-rule:
    schema-pattern: "test_*"
    table-pattern: "t_*"
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore

过滤 TiDB parser 不支持的 SQL 语句
对于 TiDB parser 不支持的 SQL 语句,DM 无法解析获得 schema/table 信息,因此需要使用全局过滤规则:schema-pattern: “*"。
注意
全局过滤规则的设置必须尽可能严格,以避免过滤掉需要迁移的数据。
可设置如下规则过滤某些版本的 TiDB parser 不支持的 PARTITION 语句:
filters:
  filter-partition-rule:
    schema-pattern: "*"
    sql-pattern: ["ALTER\\s+TABLE[\\s\\S]*ADD\\s+PARTITION", "ALTER\\s+TABLE[\\s\\S]*DROP\\s+PARTITION"]
    action: Ignore