一、配置文件
vi /etc/my.cnf
#log
binlog-format=ROW
binlog_cache_size=256K
log-bin=mysql_binlog
relay_log=mysql-relay-bin
log-error=mysqld.log
slow_query_log = on
long_query_time = 5
slow_query_log_file =mysql_slow_log
log_queries_not_using_indexes=1
#binlog_rows_query_log_events=1
#global log_bin_trust_function_creators =1
执行命令:
/usr/local/mysql/bin/mysqlbinlog -d preloan -v --start-datetime='2021-06-21 17:30:00' --stop-datetime='2021-06-21 18:50:00' -v mysql_binlog.000004 | grep INSERT
结果如下:
### INSERT INTO `preloan`.`account_balance`
### INSERT INTO `preloan`.`account_balance`
### INSERT INTO `preloan`.`account_balance`
二、配置文件
vi /etc/my.cnf
#log
binlog-format=ROW
binlog_cache_size=256K
log-bin=mysql_binlog
relay_log=mysql-relay-bin
log-error=mysqld.log
slow_query_log = on
long_query_time = 5
slow_query_log_file =mysql_slow_log
log_queries_not_using_indexes=1
binlog_rows_query_log_events=1
#global log_bin_trust_function_creators =1
重启mysql 服务后,再次执行/usr/local/mysql/bin/mysqlbinlog -d preloan -v --start-datetime='2021-06-21 17:30:00' --stop-datetime='2021-06-21 18:50:00' -v mysql_binlog.000004 | grep INSERT
结果如下:
# INSERT INTO `preloan`.`account_balance`(`id`, `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES (664, 'c2c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC620', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c2c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC620', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c3c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC630', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c2c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC620', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# -- ###INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c3c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC630', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c2c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC620', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
# INSERT INTO `preloan`.`account_balance`( `account_uuid`, `product_code`, `account_no`, `query_time`, `account_balance`, `gmt_create`, `gmt_modified`) VALUES ( 'c3c0da7b-c5d3-4e56-8765-c06605038eea', 'NBPOC630', '5123410000000002', '2021-06-11 20:35:54', 1100000000.00, '2021-01-07 15:29:42', '2021-06-11 20:35:54')
### INSERT INTO `preloan`.`account_balance`
三、总结
my.cnf中binlog_rows_query_log_events=1会让mysql_binlog.000004日志文件详细记录增删改数据库内容