binlog分析方法
线上处理问题的时候经常遇到业务说写入了但是数据不对,这种情况八成是业务改了之后又改过来了。但是我们需要证据,下面我们就说说简单的binlog分析
工具:mysqlbinlog
#-vvv显示明文sql内容方便查阅 #start-datetime分析开始时间 #stop-datatime分析结束时间 #-d数据库名称 #mysql-bin.000001 二进制文件 $mysqlbinlog -vvv --start-datetime= '2018-11-15 18:47:00' --stop-datetime= '2018-11-15 18:59:01' -uxxxxx --socket= /export/data/mysql/tmp/mysql .socket --port=3358 -d xxxxx mysql-bin.000001 > 1.txt #通过执行以上命令就可以获取这个时间段里面的binlog信息 |
以下是部分解析出来的内容,文件里面有时间戳,可以根据时间戳就判断某个操作是否执行
# at 590290541 #181115 18:47:00 server id 23083726 end_log_pos 590290606 CRC32 0x644652ac GTID last_committed=210987 sequence_number=210988 rbr_only=yes /*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED *//*!*/; SET @@SESSION.GTID_NEXT= 'd2eabe2a-d5cb-11e8-a72a-fa169c5fc76e:191960' /*!*/; # at 590290606 #181115 18:47:00 server id 23083726 end_log_pos 590290695 CRC32 0xcdd93a59 Query thread_id=95124 exec_time=0 error_code=0 SET TIMESTAMP =1542278820/*!*/; SET @@session.pseudo_thread_id=95124/*!*/; SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/; SET @@session.sql_mode=1073741824/*!*/; SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/; /*!\C utf8mb4 *//*!*/; SET @@session.character_set_client=45,@@session.collation_connection=45,@@session.collation_server=45/*!*/; SET @@session.time_zone= 'SYSTEM' /*!*/; SET @@session.lc_time_names=0/*!*/; SET @@session.collation_database= DEFAULT /*!*/; BEGIN /*!*/; # at 590290695 #181115 18:47:00 server id 23083726 end_log_pos 590291436 CRC32 0xf28f1bd8 Rows_query # insert into xxxxx(do_no, group_key, wave_strategy, auto_able, expect_pick_time, partitions, loc_code_list, priority, wms_sku_list, merge_no, weight, volume, area_id, area_name, latitude, longitude, wh_id, tenant_id, uuid, create_time, wh_name, wh_code, expect_arrive_starttime, expect_arrive_endtime, do_create_date, genera_source, extend_data) values ( '65000372273101' , 'sell_default' , 0, 1, '2018-11-15 19:18:00' , null , '[\"36518\",\"40001\"]' , 5, '[1007116,1002291,1011345]' , null , 4.580, 14178.416, 200030, '褐石园区' , '40.016893' , '116.322341' , 131231, 1, '65000372273101-1' , now(), '五彩城店' , 'WCC' , '2018-11-15 19:30:00' , '2018-11-15 20:15:00' , '2018-11-15 18:47:00' , 'AI' , '{\"workFood\":\"1\"}' ) # at 590291436 #181115 18:47:00 server id 23083726 end_log_pos 590291571 CRC32 0x3a2c02ea Table_map: `xxxxxx`.`wms_ai_do` mapped to number 262 # at 590291571 #181115 18:47:00 server id 23083726 end_log_pos 590291874 CRC32 0x8f14b7cb Write_rows: table id 262 flags: STMT_END_F |