本文介绍了如何使用SHOW BINLOG EVENTS语句查看Binlog文件中的具体事件信息。
语法
SHOW BINLOG EVENTS [WITH stream_name]
说明:
- 执行上述SQL需要有REPLICATION SLAVE权限,权限操作请参见账号权限管理。
- 不加
WITH
子句,可查看单流服务中global binlog文件中的事件信息。 - 添加
WITH
子句,可查看多流服务中某个流下面的binlog文件中的事件信息。参数stream_name
表示某个具体的流名称。 - 更多详情,请参见SHOW BINLOG EVENTS。
示例1
执行以下语句,查看单流服务中global binlog文件中的事件信息。
SHOW BINLOG EVENTS;
返回结果如下:
+---------------+------+------------+-----------+-------------+--------------------------------------------------------+
| LOG_NAME | POS | EVENT_TYPE | SERVER_ID | END_LOG_POS | INFO |
+---------------+------+------------+-----------+-------------+--------------------------------------------------------+
| binlog.000001 | 745 | Query | 1 | 807 | BEGIN |
| binlog.000001 | 807 | Table_map | 1 | 868 | table_id: 258 (transfer_test.accounts) |
| binlog.000001 | 868 | Write_rows | 1 | 912 | table_id: 258 flags: STMT_END_F |
| binlog.000001 | 912 | Table_map | 1 | 973 | table_id: 367 (transfer_test.accounts) |
| binlog.000001 | 973 | Write_rows | 1 | 1017 | table_id: 367 flags: STMT_END_F |
| binlog.000001 | 1017 | Table_map | 1 | 1078 | table_id: 366 (transfer_test.accounts) |
| binlog.000001 | 1078 | Write_rows | 1 | 1122 | table_id: 366 flags: STMT_END_F |
| binlog.000001 | 1122 | Table_map | 1 | 1183 | table_id: 365 (transfer_test.accounts) |
| binlog.000001 | 1183 | Write_rows | 1 | 1227 | table_id: 365 flags: STMT_END_F |
| binlog.000001 | 1227 | Table_map | 1 | 1288 | table_id: 365 (transfer_test.accounts) |
| binlog.000001 | 1288 | Write_rows | 1 | 1332 | table_id: 365 flags: STMT_END_F |
| binlog.000001 | 1332 | Xid | 1 | 1363 | COMMIT /* xid=1 */ |
| binlog.000001 | 1363 | Rows_query | 1 | 1441 | 677707399066754342413081391897447014400000000000132369 |
+---------------+------+------------+-----------+-------------+--------------------------------------------------------+
示例2
执行以下语句,查看多流服务中group1_stream_0流下面的group1_stream_0_binlog.000001文件中的事件信息。
SHOW BINLOG EVENTS WITH 'group1_stream_0' IN 'group1_stream_0_binlog.000001' LIMIT 10;
返回结果如下:
+-------------------------------+-----+-------------+------------+-------------+-------------------------------------------------------------+
| LOG_NAME | POS | EVENT_TYPE | SERVER_ID | END_LOG_POS | INFO |
+-------------------------------+-----+-------------+------------+-------------+-------------------------------------------------------------+
| group1_stream_0#binlog.000001 | 4 | Format_desc | 2065077497 | 123 | Server ver: 5.6.29-TDDL-5.4.13-16504348, Binlog ver: 4 |
| group1_stream_0#binlog.000001 | 123 | Rows_query | 2065077497 | 206 | CTS::692310358647373830414541688019972300810000000000640450 |
| group1_stream_0#binlog.000001 | 206 | Rows_query | 2065077497 | 289 | CTS::692310358730001619214541688028360949770000000000640450 |
| group1_stream_0#binlog.000001 | 289 | Rows_query | 2065077497 | 372 | CTS::692310358815145990414541688036749516810000000000640450 |
| group1_stream_0#binlog.000001 | 372 | Rows_query | 2065077497 | 455 | CTS::692310358897773779214541688045138165770000000000640450 |
| group1_stream_0#binlog.000001 | 455 | Rows_query | 2065077497 | 538 | CTS::692310358982498720014541688053526732810000000000640450 |
| group1_stream_0#binlog.000001 | 538 | Rows_query | 2065077497 | 621 | CTS::692310371229027539214541689278263541770000000000640450 |
| group1_stream_0#binlog.000001 | 621 | Rows_query | 2065077497 | 704 | CTS::692310371313333049614541689286652108810000000000640450 |
| group1_stream_0#binlog.000001 | 704 | Rows_query | 2065077497 | 787 | CTS::692310371397219129614541689295040757770000000000640450 |
| group1_stream_0#binlog.000001 | 787 | Rows_query | 2065077497 | 870 | CTS::692310371481105209614541689303429324810000000000640450 |
+-------------------------------+-----+-------------+------------+-------------+-------------------------------------------------------------+