Help Center/ Relational Database Service/ FAQs/ Database Usage/ How Do I Use the mysqlbinlog Tool?
Updated on 2024-10-08 GMT+08:00

How Do I Use the mysqlbinlog Tool?

This section describes how to use the mysqlbinlog tool to locally parse binlogs.

The basic unit of binlog is the binlog event. Servers write binlog files in binary format. Therefore, if you want to display the binlog content in text format, you need to use the mysqlbinlog tool to parse the binlog. Generally, this tool is stored in the same directory as mysqld.

Invoking method: mysqlbinlog [options] log_file ...

Example: mysqlbinlog masterbin.000001

Example of binlog content:

# at 141#210309 9:28:36 server id 123 end_log_pos 245Query thread_id=3350 exec_time=11 error_code=0

  • at 141: starting position of the event in the binlog file.
  • #210309 9:28:36: timestamp information, indicating that the binlog file is written at 09:28:36 on March 9, 2021 (UTC).
  • Query thread_id: thread ID.

Common mysqlbinlog parameters:

  • --start-position: position where the decoding starts.
  • --start-datetime: time where the decoding starts.
  • --stop-position: position where the decoding stops.
  • --stop-datetime: time where the decoding stops.
  • --skip-gtids: gtid_log_event is not printed.
  • --short-form: Only statements are displayed.
  • --result-file: SQL file to which binlog decoding results are written.