Maxwell1.29.x 过滤:过滤采集指定数据库、表

说明

有两种方式可以实现过滤:

  • 配置文件方式

  • 命令方式

命令方式

通过 filter 参数配置

include

采集一张表

bin/maxwell --config db_2_kafka.properties
--filter="include:db-biz-1.table_1"

采集多张表

bin/maxwell --config db_2_kafka.properties
--filter="include:db-biz-1.table_1, include:db-biz-1.table_2"

exclude

不采集一张表

bin/maxwell --config db_2_kafka.properties
--filter="exclude:db-biz-1.table_1"

不采集多张表

bin/maxwell --config db_2_kafka.properties
--filter="exclude:db-biz-1.table_1, exclude:db-biz-1.table_2"

综合使用

先排除所有数据,只保留特定库下的一张表

bin/maxwell --config db_2_kafka.properties
--filter="exclude:*.*, include:db-biz-1.table_1"

先排除所有数据,只保留特定库下的多张表

bin/maxwell --config db_2_kafka.properties
--filter="exclude:*.*, include:db-biz-1.table_1, include:db-biz-1.table_2"

先排除所有数据,配置不同库的指定表

bin/maxwell --config db_2_kafka.properties 
--filter="exclude:*.*, include:db-biz-1.table_1, include:db-biz-1.table_2, include:db-biz-2.table_3"

配置文件方式

通过下面配置

include_dbs

只发送binlog里面这些databases的变更,以 , 号分隔,中间不要包含空格。

支持java风格的正则,如 include_tables=db1,/db\\d+/,表示 db1, db2, db3…这样的。(下面的filter都支持这种regex)

提示:这里的 dbs 指定的是真实数据库。比如binlog里面可能 use db1 但 update db2.ttt,那么maxwell生成的json database 内容是 db2。

exclude_dbs

排除指定的这些 databbases

include_tables

只发送这些表的数据变更。不只需要指定 database.

exclude_tables

排除指定的这些表

exclude_columns

不输出这些字段。如果字段名在row中不存在,则忽略这个filter。

include_column_values

1.12.0新引入的过滤项。只输出满足 column=values 的行,比如 include_column_values=bar=x,foo=y,如果有bar字段,那么只输出值为x的行,如果有foo字段,那么只输出值为y的行。
如果没有对应字段,如只有bar=x没有foo字段,那么也成立。(即不是 或,也不是 与)

配置文件例子

exclude_dbs=*
include_dbs=db-biz-1,db-biz-2
include_tables=table_1,table_2,table_3

参考:
https://blog.csdn.net/liuwei0376/article/details/114595584
https://blog.csdn.net/xiaolegeaizy/article/details/100743918


原文出处:/show_1GW1eti3WhLX.html