A command-line tool that parses MySQL binlog files (online and offline) and generates raw SQL or rollback SQL. It is a Go version of binlog2sql with various features.
- Generates raw SQL/rollback SQL (-flashback/-B)
- Supports online streaming binlog parsing/offline binlog parsing (-local -local-file)
- Filters by various conditions (-start-position, -only-dml, -sql-type, etc.)
- Can generate insert statements without primary keys (-noPK)
- Update statements can ignore unchanged columns (-simple)
- Continuous online parsing (-stop-never)
- Multithreading support (-threads)
The user used must have the SELECT, REPLICATION SLAVE, and REPLICATION CLIENT privileges.
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'your_user'@'%';The SELECT privilege is needed to query metadata information in MySQL, and the REPLICATION privileges are required for online parsing by pretending to be a MySQL slave to fetch binlogs.
| Scenario | Python binlog2sql | binlog2sql_go |
|---|---|---|
| Online parsing binlog (500M) and generating SQL file | 12m59.034s | 23.707s |
| Parsing local binlog (500M) and generating SQL file | Not supported | 28.634s |
- Parse online binlog
./binlog2sql_go -h 127.0.0.1 -u root -P 3306 -p xxx -start-file mysql-bin.000002
- Parse offline binlog and generate rollback SQL
./binlog2sql_go -h 127.0.0.1 -u root -P 3306 -p xxx -local --local-file /tmp/mysql-bin.000002 -flashback
- Continuously parse online binlog
./binlog2sql_go -h 127.0.0.1 -u root -P 3306 -p xxx -start-file mysql-bin.000002 -stop-never
- Parse only update statements in DML statements
./binlog2sql_go -h 127.0.0.1 -u root -P 3306 -p xxx -start-file mysql-bin.000002 -only-dml -sql-type update
git clone https://github.com/354441703/binlog2sql_go.git
cd binlog2sql_go
go build