协议变化

  1. binlog checksum

mysql5.6之后,支持在binlog对象中增加checksum信息,比如CRC32协议. 其原理主要是在原先binlog的末尾新增了4个byte,写入一个crc32的校验值.

对应参数说明: <http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#sysvar_binlog_checksum>

注意:

  • mysql5.6.6之后默认就会开启checksum.
  • 如果canal要开启checksum协议支持,需要设置session参数,目前canal只解析checksum,并没有对checksum进行校验

java 1. set @master_binlog_checksum= ‘@@global.binlog_checksum’

  1. INSERT/UPDATE/DELETE协议变化
1. public static final int    WRITE_ROWS_EVENT_V1      = 23;
2. public static final int    UPDATE_ROWS_EVENT_V1     = 24;
3. public static final int    DELETE_ROWS_EVENT_V1     = 25;
4. /* Version 2 of the Row events /
5. public static final int    WRITE_ROWS_EVENT         = 30;
6. public static final int    UPDATE_ROWS_EVENT        = 31;
7. public static final int    DELETE_ROWS_EVENT        = 32;

新增了version 2的协议,主要的变化,就是增加了self check extra的信息,和checksum一样保证数据的完整性.

对应参数说明: <http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#sysvar_log_bin_use_v1_row_events>

默认值为0,也就是会开启version 2协议,mysql5.5之前默认是version 1协议

  1. RowsQueryLogEvent事件新增

对应事件说明: <http://dev.mysql.com/worklog/task/?id=5404> ,(主要用途:就是在RBR模式下,也可以输出原始执行insert/update/delete的sql信息)

对应参数说明: <http://dev.mysql.com/doc/refman/5.6/en/replication-options-binary-log.html#option_mysqld_binlog-rows-query-log-events>

默认值为false,代表不开启。 如果设置为true,对应的一个事务中的LogEvent事件就会变为: (RowsQuery会出现在tableMap协议之前)

1. Query :  Begin
2. RowsQuery:   insert/update/delete sql
3. TableMap :
4. Rows :  Write/Update/DELETE
5. Query/XId
  1. 其他协议变化

  2. HEARTBEAT_LOG_EVENT = 27 ##主要用途:在mysql idle期间,发送一些heartbeat事件,对应事件的内容是上一次最后发送的LogEvent信息

  3. IGNORABLE_LOG_EVENT = 28 ## 可忽略的logEvent事件概念,这是mysql为了后续协议扩展引入的,在低版本mysql发现无法识别LogEvent时,可根据LOG_EVENT_IGNORABLE_F标志来判断是否可以直接丢弃.
  4. GTID_LOG_EVENT = 33
  5. ANONYMOUS_GTID_LOG_EVENT = 34
  6. PREVIOUS_GTIDS_LOG_EVENT = 35

目前gtid协议只是解析,并没有使用GTID发起COM_BINLOG_DUMP,后续会考虑支持.

  1. 新增type : TIME2/DATETIME2/TIMESTAMP2
1. public static final int    MYSQL_TYPE_TIMESTAMP2    = 17;
2. public static final int    MYSQL_TYPE_DATETIME2     = 18;
3. public static final int    MYSQL_TYPE_TIME2         = 19;

新增了3种mysql type类型,和5.5之前的有不同的存储格式,最可恶的是居然是采用了Big-Endian,和之前的所有事件解析litten-Endian形成一个对比,不知道mysql那帮人怎么想的

测试

  1. mysql版本: 5.6.10

  2. mysql server配置 :

1. server-id=1
2. binlog-checksum=CRC32
3. # binlog-checksum=NONE

   master-verify-checksum=1
4. slave-sql-verify-checksum=1
5. log-bin=mysql-bin
6. binlog-format=ROW
7. binlog-rows-query-log-events=true
8. log-bin-use-v1-row-events=1
9. binlog_cache_size=2M
10. max_binlog_size=512M
11. sync_binlog=0
12. character-set-server = utf8
13. # default-character-set = utf8

    collation-server = utf8_unicode_ci
14. [mysql]
15. default-storage-engine=INNODB
16. default-character-set=utf8
  1. 测试注意(需要设置master_binlog_checksum变量,和mysql server保持一致)
1. Connection connection = DriverManager.getConnection(“jdbc:mysql://10.20.144.34:3306”, “root”, “root”);
2. Statement statement = connection.createStatement();
3. statement.execute(“SET @master_binlog_checksum=’@@global.binlog_checksum’”);