mysql binlog配置,StreamSets MySQL Binlog解析配置

MySQLbinlog日志作为用于MySQL主从复制的途径。 MySQL复制允许通过binlog维护多个将数据从主服务器复制到从属服务器的副本。 StreamSets可以从MySQL主数据库捕获更改,然后将更改的数据传递到Data Collector管道。

GTID是MySQL数据库事务的全局唯一ID,在MySQL中无论GTID是否打开都可以通过StreamSets处理MySQL binglog。

MySQL binlog文件提供了MySQL数据库的变化记录信息,包含有字段变化的映射记录。只包含insert,update,delete记录。在启动MySQL binlog解析之前你可以通过一个单独的pipeline 使用JDBC Query Consumeror 或者JDBC Multitable Consumer去读取MySQL之前已经存在的数据。

在配置MySQL binlog解析时,我们可以指定MySQL binlog的解析位置,或者从开始读取(beginning)。MySQL的连接可以使用用户认证或者SSL认证,还可以指定表进行复制,或者单独排除某些不需要的表。

安装配置:

1,初始化JDBC Drive

在启动MySQL binlog解析同步之前,我们必须先添加MySQL JDBC drive到streamsets,否则是无法连接MySQL的。MySQL JDBC drive添加的路径为:

example: /app/streamsets/streamsets-datacollector-mysql-binlog-lib/lib/mysql-connector-java-5.1.41-bin.jar

2,初始化offset

在启动MySQL binlog解析同步之前,我们还可以对起始同步的binlog offset进行指定,在指定offset之后 StreamSets pipeline会从该位置一直持续的同步数据,直到streamsets停止为止。

offset的设置格式根据GTID的开启与否有以下不同:

GTID enabled

当MySQL GTID打开时,MySQL binlog的初始化offset包含一个GTID,格式如下:

:

例如: 8720bebf-bb38-11e6-97b1-0242ac110004:7066

GTID disabled

当MySQL GTID关闭时,MySQL binlog包含binlog文件名和日志偏移量:

:

列如:mysql-bin.000004:587

注意:如果在使用MySQL binlog 解析管道后更改数据库服务器上的GTID模式,则必须重置offset并更改初始偏移值的格式。 否则将无法正确读取偏移量。

当管道停止时,MySQL binlog pipeline将记录其停止读取的偏移量。 当pipeline再次启动时,将从上一次保存的偏移继续进行处理。 您可以重置offset来处理所有请求的对象。

CRUD operation type

MySQL在binlog中为每个事务生成一个记录。 该记录包括包含操作类型,更改数据捕获信息和已更改数据的字段和记录头属性。

注意:如果将binlog中记录的事务回滚到MySQL数据库中,MySQL将原始事务保留在日志中,然后记录回滚事务。 因此,MySQL binlog可以处理在原始事务和回滚事务。

每个生成的记录包括以下信息:

 CRUD操作类型

 CRUD操作类型存储在类型记录字段中,也存储在sdc.operation.type记录头属性中。

 类型字段包含以下字符串值之一:INSERT,DELETE或UPDATE。

sdc.operation.type记录头属性包含以下数值之一:

1用于插入数据

2用于删除数据

3用于更新数据

可以使用类型记录字段或sdc.operation.type记录头属性将记录写入目标系统。 支持CRUD的目标,例如JDBC Producer和Kudu,使用sdc.operation.type头属性。

Change data capture information

更改数据捕获信息存储在以下记录字段中:

BinLogFilename - 禁用GTID时

BinLogPosition - 禁用GTID时

SeqNo - 启用GTID时

GTID - 启用GTID时

table

ServerId

database

timestamp

offset

New data:

包含要插入或更新的新数据的字段显示在“数据映射”字段中。

Changed data

包含要更新的旧数据或删除记录中的字段的字段将显示在OldData映射字段中。

例如,当从启用GTID的MySQL服务器的二进制日志文件中读取时,将生成以下记录:

Configuring a MySQL Binary Log Origin

Configure a MySQL Binary Log origin to process change data capture (CDC) information provided by MySQL binary logs.

In the Properties panel, on the General tab, configure the following properties:

General Property Description

Name Stage name.

Description Optional description.

On Record Error Error record handling for the stage:

• Discard - Discards the record.

• Send to Error - Sends the record to the pipeline for error handling.

• Stop Pipeline - Stops the pipeline.

On the MySQL Binary Log tab, configure the following properties:

MySQL Binary Log Property Description

Hostname MySQL server hostname.

Port MySQL server port.

Server ID Replication server ID that the origin uses to connect to the master MySQL server. Must be unique from the server ID of the replication master and of all the other replication slaves.

When the MySQL server database is enabled for GTID, the server ID is optional.

Start from Beginning Specifies whether to start reading events from the beginning of the binary log. When not selected, the origin begins reading events from the last saved offset.

Initial Offset Read events starting at this offset in the binary log.

If you configure an initial offset value and configure the origin to start from the beginning, then the origin starts reading from the initial offset.

On the Credentials tab, configure the following properties:

Credentials Property Description

Username MySQL username.

The user must have the REPLICATION SLAVE MySQL privilege.

Password MySQL password.

Tip: To secure sensitive information such as usernames and passwords, you can use runtime resources or Hashicorp Vault secrets. For more information, see Using Runtime Resources or Accessing Hashicorp Vault Secrets.

On the Advanced tab, configure the following properties:

Advanced Property Description

Batch Wait Time (ms) Number of milliseconds to wait before sending a partial or empty batch.

Max Batch Size (records) Maximum number of records processed at one time. Honors values up to the Data Collector maximum batch size.

Default is 1000. The Data Collector default is 1000.

Connection Timeout (ms) Maximum time in milliseconds to wait for a connection to the MySQL server.

Use SSL Specifies whether to use SSL/TLS to connect to the MySQL server.

Include Tables List of tables to include when reading change events in the binary log file.

Ignore Tables List of tables to ignore when reading change events in the binary log file.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值