mysql 5.7后通过设置binlog_rows_query_log_events为on,可以在binlog_format=row中记录执行的SQL语句。
mysql> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update t1 set name='tt' where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
#160418 14:39:23 server id 11 end_log_pos 662 CRC32 0x94bcfba8 Query thread_id=112 exec_time=0 error_code=0
SET TIMESTAMP=1460961563/*!*/;
BEGIN
/*!*/;
# at 662
#160418 14:39:23 server id 11 end_log_pos 712 CRC32 0x0559e4ae Table_map: `mytest`.`t1` mapped to number 112
# at 712
#160418 14:39:23 server id 11 end_log_pos 764 CRC32 0x7fafe939 Update_rows: table id 112 flags: STMT_END_F
BINLOG '
G4EUVxMLAAAAMgAAAMgCAAAAAHAAAAAAAAEABm15dGVzdAACdDEAAgMPAkAAA67kWQU=
G4EUVx8LAAAANAAAAPwCAAAAAHAAAAAAAAEAAgAC///8AgAAAAJubvwCAAAAAnR0Oemvfw==
'/*!*/;
### UPDATE `mytest`.`t1`
### WHERE
### @1=2 /* INT meta=0 nullable=1 is_null=0 */
### @2='nn' /* VARSTRING(64) meta=64 nullable=1 is_null=0 */
### SET
### @1=2 /* INT meta=0 nullable=1 is_null=0 */
### @2='tt' /* VARSTRING(64) meta=64 nullable=1 is_null=0 */
# at 764
#160418 14:39:23 server id 11 end_log_pos 795 CRC32 0x82e2d934 Xid = 1103
COMMIT/*!*/;
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
mysql> set global binlog_rows_query_log_events=on;
mysql> update t1 set name='bb' where id=2;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
BEGIN
/*!*/;
# at 934
#160418 14:46:59 server id 11 end_log_pos 992 CRC32 0x930e3483 Rows_query
# update t1 set name='bb' where id=2
# at 992
#160418 14:46:59 server id 11 end_log_pos 1042 CRC32 0x5b228624 Table_map: `mytest`.`t1` mapped to number 112
# at 1042
#160418 14:46:59 server id 11 end_log_pos 1094 CRC32 0x873d8144 Update_rows: table id 112 flags: STMT_END_F
BINLOG '
44IUVx0LAAAAOgAAAOADAACAACJ1cGRhdGUgdDEgc2V0IG5hbWU9J2JiJyB3aGVyZSBpZD0ygzQO
kw==
44IUVxMLAAAAMgAAABIEAAAAAHAAAAAAAAEABm15dGVzdAACdDEAAgMPAkAAAySGIls=
44IUVx8LAAAANAAAAEYEAAAAAHAAAAAAAAEAAgAC///8AgAAAAJ0dPwCAAAAAmJiRIE9hw==
'/*!*/;
### UPDATE `mytest`.`t1`
### WHERE
### @1=2 /* INT meta=0 nullable=1 is_null=0 */
### @2='tt' /* VARSTRING(64) meta=64 nullable=1 is_null=0 */
### SET
### @1=2 /* INT meta=0 nullable=1 is_null=0 */
### @2='bb' /* VARSTRING(64) meta=64 nullable=1 is_null=0 */
# at 1094
#160418 14:46:59 server id 11 end_log_pos 1125 CRC32 0xc28c3292 Xid = 1116
COMMIT/*!*/;
Query OK, 0 rows affected (0.00 sec)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26390465/viewspace-2083346/,如需转载,请注明出处,否则将追究法律责任。