The following examples illustrate how mysqlbinlog displays row events that specify data modifications. 以下示例说明了mysqlbinlog如何显示指定数据修改的行事件。These correspond to events with the 这些对应于具有WRITE_ROWS_EVENT
, UPDATE_ROWS_EVENT
, and DELETE_ROWS_EVENT
type codes. WRITE_ROWS_EVENT
、UPDATE_ROWS_VENT
和DELETE_ROWS_EVENT
类型代码的事件。The --base64-output=DECODE-ROWS
and --verbose
options may be used to affect row event output.--base64-output=DECODE-ROWS
和--verbose
选项可用于影响行事件输出。
Suppose that the server is using row-based binary logging and that you execute the following sequence of statements:假设服务器正在使用基于行的二进制日志记录,并且您执行了以下语句序列:
CREATE TABLE t ( id INT NOT NULL, name VARCHAR(20) NOT NULL, date DATE NULL ) ENGINE = InnoDB; START TRANSACTION; INSERT INTO t VALUES(1, 'apple', NULL); UPDATE t SET name = 'pear', date = '2009-01-01' WHERE id = 1; DELETE FROM t WHERE id = 1; COMMIT;
By default, mysqlbinlog displays row events encoded as base-64 strings using 默认情况下,mysqlbinlog使用BINLOG
statements. BINLOG
语句显示编码为base-64字符串的行事件。Omitting extraneous lines, the output for the row events produced by the preceding statement sequence looks like this:省略多余的行,由前面的语句序列生成的行事件的输出如下:
shell> mysqlbinlog log_file
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
To see the row events as comments in the form of “pseudo-SQL” statements, run mysqlbinlog with the 要将行事件视为“伪SQL”语句形式的注释,请使用--verbose
or -v
option. --verbose
或-v
选项运行mysqlbinlog。This output level also shows table partition information where applicable. The output contains lines beginning with 此输出级别还显示适用的表分区信息。输出包含以###
:###
开头的行:
shell> mysqlbinlog -v log_file
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
### INSERT INTO test.t
### SET
### @1=1
### @2='apple'
### @3=NULL
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
### UPDATE test.t
### WHERE
### @1=1
### @2='apple'
### @3=NULL
### SET
### @1=1
### @2='pear'
### @3='2009:01:01'
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
### DELETE FROM test.t
### WHERE
### @1=1
### @2='pear'
### @3='2009:01:01'
Specify 如果--verbose
or -v
twice to also display data types and some metadata for each column, and informational log events such as row query log events if the binlog_rows_query_log_events
system variable is set to TRUE
. binlog_rows_query_log_events
系统变量设置为TRUE
,则指定--verbose
或-v
两次,以显示每列的数据类型和一些元数据,以及信息日志事件,如行查询日志事件。The output contains an additional comment following each column change:输出包含每列更改后的附加注释:
shell> mysqlbinlog -vv log_file
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAANoAAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBcBAAAAKAAAAAIBAAAQABEAAAAAAAEAA//8AQAAAAVhcHBsZQ==
'/*!*/;
### INSERT INTO test.t
### SET
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAC4BAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBgBAAAANgAAAGQBAAAQABEAAAAAAAEAA////AEAAAAFYXBwbGX4AQAAAARwZWFyIbIP
'/*!*/;
### UPDATE test.t
### WHERE
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='apple' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3=NULL /* VARSTRING(20) meta=0 nullable=1 is_null=1 */
### SET
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
BINLOG '
fAS3SBMBAAAALAAAAJABAAAAABEAAAAAAAAABHRlc3QAAXQAAwMPCgIUAAQ=
fAS3SBkBAAAAKgAAALoBAAAQABEAAAAAAAEAA//4AQAAAARwZWFyIbIP
'/*!*/;
### DELETE FROM test.t
### WHERE
### @1=1 /* INT meta=0 nullable=0 is_null=0 */
### @2='pear' /* VARSTRING(20) meta=20 nullable=0 is_null=0 */
### @3='2009:01:01' /* DATE meta=0 nullable=1 is_null=0 */
You can tell mysqlbinlog to suppress the 您可以通过使用BINLOG
statements for row events by using the --base64-output=DECODE-ROWS
option. --base64-output=DECODE-ROWS
选项告诉mysqlbinlog抑制行事件的BINLOG
语句。This is similar to 这类似于--base64-output=NEVER
but does not exit with an error if a row event is found. --base64-output=NEVER
,但如果发现行事件,则不会退出并出错。The combination of --base64-output=DECODE-ROWS
and --verbose
provides a convenient way to see row events only as SQL statements:-base64-output=DECODE-ROWS
和--verbose
的组合提供了一种只将行事件视为SQL语句的方便方法:
shell> mysqlbinlog -v --base64-output=DECODE-ROWS log_file
...
# at 218
#080828 15:03:08 server id 1 end_log_pos 258 Write_rows: table id 17 flags: STMT_END_F
### INSERT INTO test.t
### SET
### @1=1
### @2='apple'
### @3=NULL
...
# at 302
#080828 15:03:08 server id 1 end_log_pos 356 Update_rows: table id 17 flags: STMT_END_F
### UPDATE test.t
### WHERE
### @1=1
### @2='apple'
### @3=NULL
### SET
### @1=1
### @2='pear'
### @3='2009:01:01'
...
# at 400
#080828 15:03:08 server id 1 end_log_pos 442 Delete_rows: table id 17 flags: STMT_END_F
### DELETE FROM test.t
### WHERE
### @1=1
### @2='pear'
### @3='2009:01:01'
You should not suppress 如果您打算重新执行mysqlbinlog输出,则不应抑制BINLOG
statements if you intend to re-execute mysqlbinlog output.BINLOG
语句。
The SQL statements produced by 由--verbose
for row events are much more readable than the corresponding BINLOG
statements. --verbose
为行事件生成的SQL语句比相应的BINLOG
语句可读性高得多。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 原始列名将丢失,并替换为@
, where N
N
is a column number.@N
,其中N
是列号。
Character set information is not available in the binary log, which affects string column display:二进制日志中没有字符集信息,这会影响字符串列的显示:
There is no distinction made between corresponding binary and nonbinary string types (对应的二进制和非二进制字符串类型(BINARY
and CHAR
, VARBINARY
and VARCHAR
, BLOB
and TEXT
). BINARY
和CHAR
、VARBINARY
与VARCHAR
、BLOB
和TEXT
)之间没有区别。The output uses a data type of 输出对固定长度字符串使用STRING
for fixed-length strings and VARSTRING
for variable-length strings.STRING
数据类型,对可变长度字符串使用VARSTRING
数据型。
For multibyte character sets, the maximum number of bytes per character is not present in the binary log, so the length for string types is displayed in bytes rather than in characters. 对于多字节字符集,二进制日志中不存在每个字符的最大字节数,因此字符串类型的长度以字节而不是字符显示。For example, 例如,STRING(4)
is used as the data type for values from either of these column types:STRING(4)
用作以下任一列类型的值的数据类型:
CHAR(4) CHARACTER SET latin1 CHAR(2) CHARACTER SET ucs2
Due to the storage format for events of type 由于UPDATE_ROWS_EVENT
, UPDATE
statements are displayed with the WHERE
clause preceding the SET
clause.UPDATE_ROWS_EVENT
类型的事件的存储格式,UPDATE
语句在SET
子句之前显示WHERE
子句。
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 因为mysqlbinlog事先不知道日志的其余部分是否包含行事件,所以默认情况下,它在输出的初始部分使用BINLOG
statement in the initial part of the output.BINLOG
语句显示格式描述事件。
If the binary log is known not to contain any events requiring a 如果已知二进制日志不包含任何需要BINLOG
statement (that is, no row events), the --base64-output=NEVER
option can be used to prevent this header from being written.BINLOG
语句的事件(即没有行事件),则可以使用--base64-output=NEVER
选项来防止写入此标头。