mysqlbinlog 命令行

常见的选项

mysqlbinlog常见的选项有一下几个:

a、--start-datetime:从二进制日志中读取指定等于时间戳或者晚于本地计算机的时间。

b、--stop-datetime:从二进制日志中读取指定小于时间戳或者等于本地计算机的时间 取值和上述一样。

c、--start-position:从二进制日志中读取指定position 事件位置作为开始。

d、--stop-position:从二进制日志中读取指定position 事件位置作为事件截至。

总结参数:

--no-defaults 不读取默认的mysql配置文件

--base64-output=decode-rows

-v,--verbose

常用的binlog日志操作命令

1、查看所有binlog日志列表

> show master logs;
  • 1.

2、查看master状态,即最后(最新)一个binlog日志的编号名称,及其最后一个操作事件pos结束点(Position)值。

> show master status;
  • 1.

3、flush 刷新log日志,自此刻开始产生一个新编号的binlog日志文件;

> flush logs;
  • 1.

注意:每当mysqld服务重启时,会自动执行此命令,刷新binlog日志;在mysqlddump备份数据时加-F选项也会刷新binlog日志;

4、重置(清空)所有binlog日志

reset master;
  • 1.

ROW 格式解析

row格式的binlog日志是用事务的方式在记,只记录了数据的修改信息,一个BEGIN为开始COMMIT结束。

BEGIN
/*事务开始*/;
# at 354
#221121 23:18:02 server id 1001  end_log_pos 448 CRC32 0x919d2dbd       Table_map: `ecology`.`modedatashare_20` mapped to number 727439
# at 448    /*位置点信息,一个位置点的结束点也是另外一个位置的起始点*/
            /* end_log_pos 556*/ 结束的位置点信息
#221121 23:18:02 server id 1001  end_log_pos 556 CRC32 0xd0b988ee       Write_rows: table id 727439 flags: STMT_END_F
### INSERT INTO `ecology`.`modedatashare_20`
### SET
###   @1=1598149074 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=3550782 /* INT meta=0 nullable=1 is_null=0 */
###   @3=1 /* INT meta=0 nullable=1 is_null=0 */
###   @4=62 /* INT meta=0 nullable=1 is_null=0 */
###   @5=0 /* INT meta=0 nullable=1 is_null=0 */
###   @6=1 /* INT meta=0 nullable=1 is_null=0 */
###   @7=89 /* INT meta=0 nullable=1 is_null=0 */
###   @8=1538 /* INT meta=0 nullable=1 is_null=0 */
###   @9=1 /* INT meta=0 nullable=1 is_null=0 */
###   @10=-1 (4294967295) /* INT meta=0 nullable=1 is_null=0 */
###   @11=-1 (4294967295) /* INT meta=0 nullable=1 is_null=0 */
###   @12=-1 (4294967295) /* INT meta=0 nullable=1 is_null=0 */
###   @13=NULL /* LONGINT meta=0 nullable=1 is_null=1 */
###   @14=3 /* INT meta=0 nullable=1 is_null=0 */
###   @15=615420594 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @16=141 /* INT meta=0 nullable=1 is_null=0 */
###   @17=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @18=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @19=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @20=NULL /* VARSTRING(3000) meta=3000 nullable=1 is_null=1 */
###   @21=NULL /* INT meta=0 nullable=1 is_null=1 */
# at 556
#221121 23:18:02 server id 1001  end_log_pos 587 CRC32 0x182a473c       Xid = 13557849555
COMMIT/*!*/;
# at 587
#221121 23:18:02 server id 1001  end_log_pos 666 CRC32 0x935df960       GTID    last_committed=1        sequence_number=2       rbr_only=yes    original_committed_timestamp=1669043882416288   immediate_commit_timestamp=1669043882416288     transaction_length=390
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
# original_commit_timestamp=1669043882416288 (2022-11-21 23:18:02.416288 CST)
# immediate_commit_timestamp=1669043882416288 (2022-11-21 23:18:02.416288 CST)
/*!80001 SET @@session.original_commit_timestamp=1669043882416288*//*!*/;
/*!80014 SET @@session.original_server_version=80030*//*!*/;
/*!80014 SET @@session.immediate_server_version=80030*//*!*/;
SET @@SESSION.GTID_NEXT= '72a26792-1875-11ed-a9e8-fa163e7d76e1:53326684'/*!*/;
# at 666
#221121 23:18:02 server id 1001  end_log_pos 744 CRC32 0x56e65c27       Query   thread_id=368009        exec_time=0     error_code=0
SET TIMESTAMP=1669043882/*!*/;
BEGIN
/*!*/;
# at 744
#221121 23:18:02 server id 1001  end_log_pos 838 CRC32 0xf8b8d980       Table_map: `ecology`.`modedatashare_20` mapped to number 727439
# at 838
#221121 23:18:02 server id 1001  end_log_pos 946 CRC32 0x0beddcce       Write_rows: table id 727439 flags: STMT_END_F
### INSERT INTO `ecology`.`modedatashare_20`
### SET
###   @1=1598149075 /* LONGINT meta=0 nullable=0 is_null=0 */
###   @2=3550782 /* INT meta=0 nullable=1 is_null=0 */
###   @3=1 /* INT meta=0 nullable=1 is_null=0 */
###   @4=1538 /* INT meta=0 nullable=1 is_null=0 */
###   @5=-999999 (4293967297) /* INT meta=0 nullable=1 is_null=0 */
###   @6=1 /* INT meta=0 nullable=1 is_null=0 */
###   @7=1000 /* INT meta=0 nullable=1 is_null=0 */
###   @8=6724 /* INT meta=0 nullable=1 is_null=0 */
###   @9=1 /* INT meta=0 nullable=1 is_null=0 */
###   @10=0 /* INT meta=0 nullable=1 is_null=0 */
###   @11=0 /* INT meta=0 nullable=1 is_null=0 */
###   @12=-1 (4294967295) /* INT meta=0 nullable=1 is_null=0 */
###   @13=NULL /* LONGINT meta=0 nullable=1 is_null=1 */
###   @14=1 /* INT meta=0 nullable=1 is_null=0 */
###   @15=615420595 /* LONGINT meta=0 nullable=1 is_null=0 */
###   @16=3396 /* INT meta=0 nullable=1 is_null=0 */
###   @17=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @18=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @19=NULL /* INT meta=0 nullable=1 is_null=1 */
###   @20=NULL /* VARSTRING(3000) meta=3000 nullable=1 is_null=1 */
###   @21=NULL /* INT meta=0 nullable=1 is_null=1 */
# at 946
#221121 23:18:02 server id 1001  end_log_pos 977 CRC32 0xf3cdca2b       Xid = 13557849575
COMMIT/*!*/;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.