MySQL 查看 binlog 文件的方式
使用show binlog events
mysql> show binary logs; +------------------+-----------+ | Log_name | File_size | +------------------+-----------+ | mysql-bin.000001 | 408006 | | mysql-bin.000002 | 1516 | +------------------+-----------+ 2 rows in set (0.00 sec) mysql> show binlog events in 'mysql-bin.000002'; +------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------+ | Log_name | Pos | Event_type | Server_id | End_log_pos | Info | +------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------+ | mysql-bin.000002 | 4 | Format_desc | 2 | 123 | Server ver: 5.7.21-log, Binlog ver: 4 | | mysql-bin.000002 | 123 | Previous_gtids | 2 | 154 | | | mysql-bin.000002 | 154 | Anonymous_Gtid | 2 | 219 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 219 | Query | 2 | 296 | BEGIN | | mysql-bin.000002 | 296 | Table_map | 2 | 351 | table_id: 108 (test_repl.user) | | mysql-bin.000002 | 351 | Write_rows | 2 | 398 | table_id: 108 flags: STMT_END_F | | mysql-bin.000002 | 398 | Xid | 2 | 429 | COMMIT /* xid=26 */ | | mysql-bin.000002 | 429 | Anonymous_Gtid | 2 | 494 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 494 | Query | 2 | 609 | create database test_regexp | | mysql-bin.000002 | 609 | Anonymous_Gtid | 2 | 674 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 674 | Query | 2 | 801 | create database test_regexp_u_1 | | mysql-bin.000002 | 801 | Anonymous_Gtid | 2 | 866 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 866 | Query | 2 | 1025 | use `test_regexp_u_1`; create table books (id int not null, name varchar(64) not null) | | mysql-bin.000002 | 1025 | Anonymous_Gtid | 2 | 1090 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 1090 | Query | 2 | 1173 | BEGIN | | mysql-bin.000002 | 1173 | Table_map | 2 | 1235 | table_id: 109 (test_regexp_u_1.books) | | mysql-bin.000002 | 1235 | Write_rows | 2 | 1285 | table_id: 109 flags: STMT_END_F | | mysql-bin.000002 | 1285 | Xid | 2 | 1316 | COMMIT /* xid=67 */ | | mysql-bin.000002 | 1316 | Anonymous_Gtid | 2 | 1381 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | | mysql-bin.000002 | 1381 | Query | 2 | 1516 | use `test_regexp`; create table students(id int, name varchar(32)) | +------------------+------+----------------+-----------+-------------+----------------------------------------------------------------------------------------+ 20 rows in set (0.00 sec) show binlog events in 'mysql-bin.000002' from 1 limit 1;
使用 mysqlbinlog 查看 binlog
mysqlbinlog --base64-output=decode-rows -v /usr/local/var/mysql/mysql-bin.000002 | less