mysql bin log 相关参数说明
binlog-do-db
如果配置了该参数,则mysql只记录该数据库的相关操作到binlog中,没有配置的数据库则不记录
binlog_error_action
从MySQL 5.6.22版本开始,引入了一个新参数binlog_error_action (5.6.20及21版本叫做binlogging_impossible_mode),若设置为ABORT_SERVER,则在发生binlog写入错误时直接让实例退出,避免引发更大的错误;若设置为IGNORE_ERROR,则忽略本次写入失败,同时禁止Binlog记录,需要重启才能让binlog再次开启。为了主备数据的强一致性,通常应该将binlog_error_action设置为ABORT_SERVER,这样在打开文件、rotate新文件、从IO Cache写binlog到文件出现磁盘错误时,都会退出实例。
sync_binlog
MySQL提供一个sync_binlog参数来控制数据库的binlog刷到磁盘上去。
默认,sync_binlog=0,表示MySQL不控制binlog的刷新,由文件系统自己控制它的缓存的刷新。这时候的性能是最好的,但是风险也是最大的。因为一旦系统Crash,在binlog_cache中的所有binlog信息都会被丢失。
如果sync_binlog>0,表示每sync_binlog次事务提交,MySQL调用文件系统的刷新操作将缓存刷下去。最安全的就是sync_binlog=1了,表示每次事务提交,MySQL都会把binlog刷下去,是最安全但是性能损耗最大的设置。这样的话,在数据库所在的主机操作系统损坏或者突然掉电的情况下,系统才有可能丢失1个事务的数据。但是binlog虽然是顺序IO,但是设置sync_binlog=1,多个事务同时提交,同样很大的影响MySQL和IO性能。虽然可以通过group commit的补丁缓解,但是刷新的频率过高对IO的影响也非常大。对于高并发事务的系统来说,“sync_binlog”设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多。
所以很多MySQL DBA设置的sync_binlog并不是最安全的1,而是100或者是0。这样牺牲一定的一致性,可以获得更高的并发和性能。
从以往经验和相关测试来看,对于高并发事务的系统来说,“sync_binlog”设置为0和设置为1的系统写入性能差距可能高达5倍甚至更多。
binlog_row_image
MySQL 5.7以后binlog的格式默认就是ROW了,同时引入了新的参数binlog_row_image,这个参数默认值是FULL,其还有一个值是minimal。
FULL记录每一行的变更,minimal只记录影响后的行。下面简单的测试一下大家就明白了。
mysql> show variables like '%row_im%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| binlog_row_image | FULL |
+------------------+-------+
1 row in set (0.01 sec)
mysql> update t2 set uid=99 where name='yayundeng';
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql>
解析binlog
[root@yayundeng 3306]# mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000010 | tail -n 20
#161210 11:02:32 server id 152 end_log_pos 2043 CRC32 0x3ce8a225 Update_rows: table id 110 flags: STMT_END_F
### UPDATE `test`.`t2`
### WHERE
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='gz' /* STRING(20) meta=65044 nullable=1 is_null=0 */
### @3='yayundeng' /* STRING(20) meta=65044 nullable=1 is_null=0 */
### @4=1 /* INT meta=0 nullable=1 is_null=0 */
### SET
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='gz' /* STRING(20) meta=65044 nullable=1 is_null=0 */
### @3='yayundeng' /* STRING(20) meta=65044 nullable=1 is_null=0 */
### @4=99 /* INT meta=0 nullable=1 is_null=0 */
# at 2043
#161210 11:02:32 server id 152 end_log_pos 2074 CRC32 0x93619126 Xid = 49
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@yayundeng 3306]#
cdc 参数说明
database.history.store.only.monitored.tables.ddl
布尔值,指定连接器是否应记录所有DDL语句,或者(如果为true)仅记录与Debezium(通过筛选器配置)监视的表相关的语句。安全默认值为false。应小心使用此功能,因为更改筛选器时可能需要缺少数据。
错误一
错误描述
org.apache.kafka.connect.errors.ConnectException
at io.debezium.connector.mysql.AbstractReader.wrap(AbstractReader.java:230)
at io.debezium.connector.mysql.AbstractReader.failed(AbstractReader.java:197)
at io.debezium.connector.mysql.BinlogReader$ReaderThreadLifecycleListener.onCommunicationFailure(BinlogReader.java:1018)
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:950)
at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:580)
at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:825)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.EOFException
at com.github.shyiko.mysql.binlog.io.ByteArrayInputStream.read(ByteArrayInputStream.java:190)
at com.github.shyiko.mysql.binlog.io.ByteArrayInputStream.readInteger(ByteArrayInputStream.java:46)
at com.github.shyiko.mysql.binlog.event.deserialization.EventHeaderV4Deserializer.deserialize(EventHeaderV4Deserializer.java:35)
at com.github.shyiko.mysql.binlog.event.deserialization.EventHeaderV4Deserializer.deserialize(EventHeaderV4Deserializer.java:27)
at com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer.nextEvent(EventDeserializer.java:212)
at io.debezium.connector.mysql.BinlogReader$1.nextEvent(BinlogReader.java:224)
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:922)
一般该错误是在CDC connector所连接的数据库宕机或者重启的情况下出现的.且在重启完成之后,不会自动变为running状态.
解决办法
重启该connector即可恢复正常.
错误二
错误描述
org.apache.kafka.connect.errors.ConnectException: could not find next log; the first event 'binlog.000030' at 155, the last event read from './binlog.000030' at 124, the last byte read from './binlog.000030' at 155. Error code: 1236; SQLSTATE: HY000.
at io.debezium.connector.mysql.AbstractReader.wrap(AbstractReader.java:230)
at io.debezium.connector.mysql.AbstractReader.failed(AbstractReader.java:197)
at io.debezium.connector.mysql.BinlogReader$ReaderThreadLifecycleListener.onCommunicationFailure(BinlogReader.java:1018)
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:950)
at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:580)
at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:825)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.github.shyiko.mysql.binlog.network.ServerException: could not find next log; the first event 'binlog.000030' at 155, the last event read from './binlog.000030' at 124, the last byte read from './binlog.000030' at 155.
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:914)
... 3 more
改错误的出现,因为执行了一次reset master
,清除了mysql的binlog日志,日志文件从新的000001开始了,导致cdc不能找到binlog文件.
解决办法
重启该connector即可恢复正常.
错误三
错误描述
CDC的主域名可以访问通,但是获取不了connectors,即http://localhost:8083/可以正常返回,但是http://localhost:8083/connectors请求超时.
解决办法
该问题一般是CDC连接kafka失败.请价差kafka状态.连接上kafka之后,改问题会自动恢复
错误四
错误描述
CDC connector状态正常,kafka状态也这很正常,binlog会产生日志,但是kafka收不到消息.
解决办法
各类错误一般是connector的配置错误,请检查connector的注册信息.包括
- table.whitelist选项的表名称前是否携带数据库信息.
错误五
错误描述
org.apache.kafka.connect.errors.ConnectException: Could not open log file Error code: 1236; SQLSTATE: HY000.
at io.debezium.connector.mysql.AbstractReader.wrap(AbstractReader.java:230)
at io.debezium.connector.mysql.AbstractReader.failed(AbstractReader.java:197)
at io.debezium.connector.mysql.BinlogReader$ReaderThreadLifecycleListener.onCommunicationFailure(BinlogReader.java:1018)
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:950)
at com.github.shyiko.mysql.binlog.BinaryLogClient.connect(BinaryLogClient.java:580)
at com.github.shyiko.mysql.binlog.BinaryLogClient$7.run(BinaryLogClient.java:825)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.github.shyiko.mysql.binlog.network.ServerException: Could not open log file
at com.github.shyiko.mysql.binlog.BinaryLogClient.listenForEventPackets(BinaryLogClient.java:914)
该错误一般是由于当前正在使用的binlog文件丢失,或者由于目中原因不能写入造成的.
解决办法
- 运行命令
show master logs;
,查看最新的binlog文件名.
P
运行命名show binlog events in 'binlog.000003';
,查看最新binlog中的事件.
P
如果显示如图所示,则证明文件已经丢失.请查看日志文件.再找回日志文件后重启connector.
错误六
错误描述
org.apache.kafka.connect.errors.ConnectException: The connector is trying to read binlog starting at binlog file 'mariadb-bin.000003', pos=63317395, skipping 0 events plus 1 rows, but this is no longer available on the server. Reconfigure the connector to use a snapshot when needed.
at io.debezium.connector.mysql.MySqlConnectorTask.start(MySqlConnectorTask.java:127)
at io.debezium.connector.common.BaseSourceTask.start(BaseSourceTask.java:49)
at org.apache.kafka.connect.runtime.WorkerSourceTask.execute(WorkerSourceTask.java:198)
at org.apache.kafka.connect.runtime.WorkerTask.doRun(WorkerTask.java:175)
at org.apache.kafka.connect.runtime.WorkerTask.run(WorkerTask.java:219)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
该错误是connector所要寻找的binlog已经不在了,无法读取.有可能是因为过期导致的.
解决办法
更新connector,snapshot.mode参数使用when_needed参数.
错误七
在注册connector的时候,返回400错误,错误信息如下:
{"error_code":400,"message":"Connector configuration is invalid and contains the following 1 error(s):\nUnable to connect: Communications link failure\n\nThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.\nYou can also find the above list of errors at the endpoint `/{connectorType}/config/validate`"}
该错误一般是由于我们注册的时候,填写的mysql的配置信息有问题,导致connector连接不上mysql数据库导致的.
解决办法
检查注册信息中的connector配置,特别是mysql链接相关的配置后,重新注册