mysql binlog查看常用命令

1、查看当前正在写入的binlog文件

show master status\G;

*************************** 1. row ***************************
             File: mysql-bin.000002
         Position: 155
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 
1 row in set (0.01 sec)

2、只查看第一个binlog文件的内容

show binlog events;
+------------------+-----+----------------+-----------+-------------+--------------------------------------+
| Log_name         | Pos | Event_type     | Server_id | End_log_pos | Info                                 |
+------------------+-----+----------------+-----------+-------------+--------------------------------------+
| mysql-bin.000001 |   4 | Format_desc    |         1 |         124 | Server ver: 8.0.13, Binlog ver: 4    |
| mysql-bin.000001 | 124 | Previous_gtids |         1 |         155 |                                      |
| mysql-bin.000001 | 155 | Anonymous_Gtid |         1 |         230 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' |
| mysql-bin.000001 | 230 | Query          |         1 |         319 | BEGIN                                |
| mysql-bin.000001 | 319 | Table_map      |         1 |         389 | table_id: 61 (or_test.person)        |
| mysql-bin.000001 | 389 | Update_rows    |         1 |         499 | table_id: 61 flags: STMT_END_F       |
| mysql-bin.000001 | 499 | Xid            |         1 |         530 | COMMIT /* xid=169 */                 |
+------------------+-----+----------------+-----------+-------------+--------------------------------------+

3、查看指定binlog文件的内容

show binlog events in 'mysql-bin.000002';

+------------------+-----+----------------+-----------+-------------+-----------------------------------+
| Log_name         | Pos | Event_type     | Server_id | End_log_pos | Info                              |
+------------------+-----+----------------+-----------+-------------+-----------------------------------+
| mysql-bin.000002 |   4 | Format_desc    |         1 |         124 | Server ver: 8.0.13, Binlog ver: 4 |
| mysql-bin.000002 | 124 | Previous_gtids |         1 |         155 |                                   |
+------------------+-----+----------------+-----------+-------------+-----------------------------------+

4、获取binlog文件列表

show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       530 |
| mysql-bin.000002 |       155 |
+------------------+-----------+

关于数据恢复的方式,小编没有验证,详情参考:
https://www.cnblogs.com/martinzhang/p/3454358.html

你可能感兴趣的:(mysql,mysql,binlog)