mysql binlog 保存日志顺序

本文探讨了MySQL binlog保存日志的顺序,通过测试发现binlog会按照时间先后记录不同会话的操作。在基于特定时间点恢复时,必须精确到能够包含所需会话的提交记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

先测试下mysql的

session1:

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into bai values(1,'a',10);
Query OK, 1 row affected (0.00 sec)
不提交,开始等待会话2提交
mysql> commit;
Query OK, 0 rows affected (0.00 sec)

session2:
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into bai values(2,'bb',11);
Query OK, 1 row affected (0.00 sec)

mysql> commit;
Query OK, 0 rows affected (0.00 sec)
开始提交session1 

看binlog日志内容,看到是先记录的会话2的时间

BEGIN
/*!*/;
# at 351
#180110 16:13:23 server id 503333  end_log_pos 401 CRC32 0xb5a1984a     Table_map: `test`.`bai` mapped to number 70
# at 401
#180110 16:13:23 server id 503333  end_log_pos 448 CRC32 0x05875047     Write_rows: table id 70 flags: STMT_END_F
### INSERT INTO `test`.`bai`
### SET
###   @1=2 /* INT meta=0 nullable=0 is_null=0 */
###   @2='bb' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
###   @3=11 /* INT meta=0 nullable=0 is_null=0 */
# at 448
#180110 16:13:25 server id 503333  end_log_pos 479 CRC32 0x29fb4565     Xid = 38599
COMMIT/*!*/;
# at 479
#180110 16:13:28 server id 503333  end_log_pos 527 CRC32 0xcb8f59cf     GTID [commit=yes]
SET @@SESSION.GTID_NEXT= 'ea24d53c-5315-11e7-b5fa-5254005bf35b:8075'/*!*/;
# at 527
#180110 16:13:05 server id 503333  end_log_pos 599 CRC32 0xb1c3647e     Query   thread_id=12757 exec_time=0 error_code=0
SET TIMESTAMP=1515571985/*!*/;
BEGIN
/*!*/;
# at 599
#180110 16:13:05 server id 503333  end_log_pos 649 CRC32 0x5e94c3a5     Table_map: `test`.`bai` mapped to number 70
# at 649
#180110 16:13:05 server id 503333  end_log_pos 695 CRC32 0x1c22224e     Write_rows: table id 70 flags: STMT_END_F
### INSERT INTO `test`.`bai`
### SET
###   @1=1 /* INT meta=0 nullable=0 is_null=0 */
###   @2='a' /* VARSTRING(60) meta=60 nullable=1 is_null=0 */
###   @3=10 /* INT meta=0 nullable=0 is_null=0 */
# at 695
#180110 16:13:28 server id 503333  end_log_pos 726 CRC32 0xb50d7718     Xid = 38597
COMMIT/*!*/;

基于stoptime的时间点恢复,如果stop时间制定到–stop-datetime=”2018-01-10 16:13:25”时看不到任何记录的,指定到–stop-datetime=”2018-01-10 16:13:26”能看到第二个会话提交的记录。指定到–stop-datetime=”2018-01-10 16:13:29”才能看到2个会话的记录。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值