这期内容当中小编将会给大家带来有关如何理解binlog的binlog_rows_query_log_events和binlog_row_image参数,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
mysql 5.6.2 引入的两个参数binlog_rows_query_log_events和binlog_row_image
对于使用row格式的binlog,个人觉得很有用;
binlog_rows_query_log_events =1
在row模式下..开启该参数,将把sql语句打印到binlog日志里面.默认是0(off);
虽然将语句放入了binlog,但不会执行这个sql,就相当于注释一样.但对于dba来说,在查看binlog的时候,很有用处.
binlog_row_image='minimal'
默认为full,在binlog为row格式下,full将记录update前后所有字段的值,minimal时,只记录更改字段的值和where字段的值,noblob时,记录除了blob和text的所有字段的值,如果update的blob或text字段,也只记录该字段更改后的值,更改前的不记录;
大家都知道row格式下的binlog增长速度太快,对存储空间,主从传输都是一个不小的压力.因为每个event记录了所有更改数据前后的值,不管数据是否有改动都会记录.binlog_row_image的引入就大大减少了binlog记录的数据.在结合binlog_rows_query_log_events,对于dba日常维护binlog是完全没有压力的,而且节省了硬盘空间开销,减小I/O,减少了主从传输压力;
下面通过举例说明:
下面就是一个事务在row格式下的binlog日志,红色部分就是binlog_rows_query_log_events后的效果;黄色部分就是binlog_row_image=full的结果,记录所有字段在更改前后的值;
# at 1134
#161118 17:25:49 server id 3310 end_log_pos 1199 CRC32 0x3d0190ce GTID last_committed=1 sequence_number=2
SET @@SESSION.GTID_NEXT= '59194c6e-70db-11e6-b85b-5254002eb131:299';
# at 1199
#161118 17:25:49 server id 3310 end_log_pos 1270 CRC32 0x0bc5f8df Query thread_id=26 exec_time=0 error_code=0
SET TIMESTAMP=1479461149;
BEGIN
;
# at 1270
#161118 17:25:49 server id 3310 end_log_pos 1332 CRC32 0x7533bf59 Rows_query
# update t11 set col7 ='xxx' where id =2 ##############这一行就是启用了binlog_rows_query_log_events后的效果;
# at 1332
#161118 17:25:49 server id 3310 end_log_pos 1396 CRC32 0x75f09d77 Table_map: `tt1`.`t11` mapped to number 137
# at 1396
#161118 17:25:49 server id 3310 end_log_pos 1929 CRC32 0xa6eb390e Update_rows: table id 137 flags: STMT_END_F
### UPDATE `tt1`.`t11`
### WHERE
### @1=2
### @2='xxx'
### @3='bbbbbbbbbbbbbbbbbbbb'
### @4='cccccccccccccccccccc'
### @5='dddddddddddddddddddd'
### @6='eeeeeeeeeeeeeeeeeeee'
### @7='ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
### @8='gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg'
### SET
### @1=2
### @2='xxx'
### @3='bbbbbbbbbbbbbbbbbbbb'
### @4='cccccccccccccccccccc'
### @5='dddddddddddddddddddd'
### @6='eeeeeeeeeeeeeeeeeeee'
### @7='ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
### @8='xxx'
# at 1929
#161118 17:25:49 server id 3310 end_log_pos 1960 CRC32 0x9d147914 Xid = 551
COMMIT;
看下面的例子:黄色部分就是binlog_row_image='minimal' 的日志.只记录了更改后的值和where值.跟上面的例子一对比就发现减少了太多记录;
# at 1960
#161118 17:26:25 server id 3310 end_log_pos 2025 CRC32 0x20921004 GTID last_committed=2 sequence_number=3
SET @@SESSION.GTID_NEXT= '59194c6e-70db-11e6-b85b-5254002eb131:300';
# at 2025
#161118 17:26:25 server id 3310 end_log_pos 2096 CRC32 0x0c129ffb Query thread_id=26 exec_time=0 error_code=0
SET TIMESTAMP=1479461185;
BEGIN
;
# at 2096
#161118 17:26:25 server id 3310 end_log_pos 2158 CRC32 0x6a5031d0 Rows_query
# update t11 set col1 ='xxx' where id =3
# at 2158
#161118 17:26:25 server id 3310 end_log_pos 2222 CRC32 0x34de716f Table_map: `tt1`.`t11` mapped to number 137
# at 2222
#161118 17:26:25 server id 3310 end_log_pos 2268 CRC32 0x77563057 Update_rows: table id 137 flags: STMT_END_F
### UPDATE `tt1`.`t11`
### WHERE
### @1=3
### SET
### @2='xxx'
# at 2268
#161118 17:26:25 server id 3310 end_log_pos 2299 CRC32 0xe9b5eaa7 Xid = 555
COMMIT;
下面看看binlog_row_image=noblob时的情况,在noblob下,跟full唯一的区别是没有记录字段类型为text和blob的值,其他的都记录了.而且在例子中特意更改了@8(col7),这是一个text类型的字段,可以看到,在set前是没有记录整个字段的,只是记录该值set后的值;
# at 3691
#161118 17:27:01 server id 3310 end_log_pos 3756 CRC32 0x59fb0d65 GTID last_committed=6 sequence_number=7
SET @@SESSION.GTID_NEXT= '59194c6e-70db-11e6-b85b-5254002eb131:304';
# at 3756
#161118 17:27:01 server id 3310 end_log_pos 3827 CRC32 0x9943381e Query thread_id=26 exec_time=0 error_code=0
SET TIMESTAMP=1479461221;
BEGIN
;
# at 3827
#161118 17:27:01 server id 3310 end_log_pos 3889 CRC32 0xa617db5e Rows_query
# update t11 set col7 ='xxx' where id =4
# at 3889
#161118 17:27:01 server id 3310 end_log_pos 3953 CRC32 0x74e30167 Table_map: `tt1`.`t11` mapped to number 137
# at 3953
#161118 17:27:01 server id 3310 end_log_pos 4180 CRC32 0xd92fe8dc Update_rows: table id 137 flags: STMT_END_F
### UPDATE `tt1`.`t11`
### WHERE
### @1=4
### @2='xxx'
### @3='bbbbbbbbbbbbbbbbbbbb'
### @4='cccccccccccccccccccc'
### @5='dddddddddddddddddddd'
### @6='eeeeeeeeeeeeeeeeeeee'
### SET
### @1=4
### @2='xxx'
### @3='bbbbbbbbbbbbbbbbbbbb'
### @4='cccccccccccccccccccc'
### @5='dddddddddddddddddddd'
### @6='eeeeeeeeeeeeeeeeeeee'
### @8='xxx'
# at 4180
#161118 17:27:01 server id 3310 end_log_pos 4211 CRC32 0x87487ec8 Xid = 561
COMMIT;
# at 4211
对于delete效果也是一样的,就不一一举例了..
BEGIN
;
# at 4347
#161118 18:46:03 server id 3310 end_log_pos 4398 CRC32 0xd76dbd23 Rows_query
# delete from t11 where id =2
# at 4398
#161118 18:46:03 server id 3310 end_log_pos 4462 CRC32 0x75656a14 Table_map: `tt1`.`t11` mapped to number 137
# at 4462
#161118 18:46:03 server id 3310 end_log_pos 4590 CRC32 0xafec2072 Delete_rows: table id 137 flags: STMT_END_F
### DELETE FROM `tt1`.`t11`
### WHERE
### @1=2
### @2='xxx'
### @3='bbbbbbbbbbbbbbbbbbbb'
### @4='cccccccccccccccccccc'
### @5='dddddddddddddddddddd'
### @6='eeeeeeeeeeeeeeeeeeee'
# at 4590
#161118 18:46:03 server id 3310 end_log_pos 4621 CRC32 0x179ae194 Xid = 562
COMMIT;
上述就是小编为大家分享的如何理解binlog的binlog_rows_query_log_events和binlog_row_image参数了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。