在使用RBR也就是行格式的时候,去解析binlog,需要逆向才能分析出对应的原始SQL是什么,而且,里面对应的是每一条具体行变更的内容。当然,你可以开启general log,但如果我们需要的只是记录对应的行变更,而不需要记录这些select普通的查询,因为general log 会将线上所有的操作都记录下来,这种功能适合于我们审核统计,但是不适合我们对事务进行判断,故此,我们使用binlog_rows_query_log_events进行查看。在官网中的解析如下
binlog_rows_query_log_events
The binlog_rows_query_log_events system variable affects row-based logging only. When enabled, it causes a MySQL 5.6.2 or later server
to write informational log events such as row query log events into its binary log. This information can be used for debugging and related purposes;
such as obtaining the original query issued on the master when it cannot be reconstructed from the row updates.
These events are normally ignored by MySQL programs reading the binary log and so cause no issues when replicating or restoring from backup.
To view them, increase the verbosity level by using mysqlbinlog's --verbose option twice, either as "-vv" or "--verbose --verbose".
可以看到,它是一个动态的,全局,会话型的变量,即可以通过SQL模式进行关闭开启。
在未开启状态中的使用
[root@localhost][boss]> flush logs;
Query OK, 0 rows affected (0.90 sec)
[root@localhost][boss]> flush logs;
Query OK, 0 rows affected (0.18 sec)
[root@gzx-master-01 logs]# ll
total 8977656
-rw-r----- 1 mysql mysql 79405 Apr 24 08:42 error.log
-rw-r----- 1 mysql mysql 217 Mar 10 10:42 mysql_bin.000013
-rw-r----- 1 my