Technology Sharing

Database reverse engineering tool reverse_sql

2024-07-08

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

reverse_sql is a tool for parsing and converting MySQL binary logs (binlog). It can convert database change operations (such as insert, update, delete) recorded in binary log files into reverse SQL statements to roll back and recover data from system or human errors.
**ps: **Binary log needs to be enabled (MySQL installed with one-click script is enabled by default)
SHOW VARIABLES LIKE ‘log_bin’;
image.png
**ps:** The binary log needs to be in ROW format (MySQL installed by one-click script defaults to ROW)
SHOW VARIABLES LIKE ‘binlog_format’;
image.png

View the binary log path

SHOW VARIABLES LIKE ‘log_bin_basename’;
image.png
image.png

Positioning requires recovery time period

  • Determine the binary log that needs to be restored based on the binary log generation time. Take ON.000706 as an example. The log records the operations between 02:01 on April 13 and 02:00 on April 14.

image.png

  • Compile the log into a readable SQL file in the binary log path

/usr/local/mysql/bin/mysqlbinlog --no-defaults --base64-output=DECODE-ROWS -v --skip-gtids ON.000706