MySQL抑制binlog日志中的binlog部分

MySQL通过binlog来记录整个数据的变更过程,因此我们只要有MySQL的binlog日志即可完整的还原数据库。MySQL binlog日志记录有3种不同的方式,即:STATEMENT,MIXED,ROW。对于不同的日志模式,生成的binlog有不同的记录方式。对于MIXED(部分SQL语句)和ROW模式是以base-64方式记录,会以BINLOG开头,是一段伪SQL,我们可以用使用base64-output参数来抑制其显示。本文对此给出了描述及演示。

有关mysqlbinlog的用法,请参考:使用mysqlbinlog提取二进制日志 

1、mysqlbinlog之base64-output参数

This option determines when events should be displayed encoded as base-64 strings using BINLOG statements. The option has these permissible values (not case sensitive):

以上描述对于binlog日志中的BINLOG部分,如果要过虑掉需要指定DECODE-ROWS 以及选项。

 

The SQL statements produced by  for row events are much more readable than the corresponding BINLOG statements. However, they do not correspond exactly to the original SQL statements that generated the events. The following limitations apply:

    选项可以获取更多的可读信息,但是并不是一个原始的SQL语句(类似的)

·        The original column names are lost and replaced by @N, where N is a column number.

·        Character set information is not available in the binary log, which affects string column display:

CHAR(4) CHARACTER SET latin1

CHAR(2) CHARACTER SET ucs2

Proper interpretation of row events requires the information from the format description event at the beginning of the binary log. Because mysqlbinlog does not know in advance whether the rest of the log contains row events, by default it displays the format description event using a BINLOG statement in the initial part of the output.

If the binary log is known not to contain any events requiring a BINLOG statement (that is, no row events), the  option can be used to prevent this header from being written.

2、演示生成binlog日志

--环境
mysql> show variables like 'version';
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version      | 5.6.12-log |
+---------------+------------+

--如下查询binlog为row记录模式
mysql> show variables like 'binlog_for%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW  |
+---------------+-------+

mysql> reset master;
Query OK, 0 rows affected (0.01 sec)

mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------+
| File            | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| APP01bin.000001 |      120 |              |                  |                  |
+-----------------+----------+--------------+------------------+-------------------+

mysql> use test;
Database changed

--创建表t1
mysql> create table t1(id smallint,val varchar(20));
Query OK, 0 rows affected (0.01 sec)

--插入单条记录
mysql> insert into t1 values(1,'robin');
Query OK, 1 row affected (0.00 sec)

--清空表
mysql> truncate table t1;
Query OK, 0 rows affected (0.01 sec)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/464d079ed40d5a50e36e13d47de06afa.html