A lightweight, production-grade MySQL/MariaDB binlog listener implemented in pure Go. It disguises itself as a MySQL slave, captures real-time DML events (INSERT, UPDATE, DELETE), and broadcasts them as structured JSON via Redis Pub/Sub.
- Protocol Compatibility: Supports MySQL 5.5+ and the latest MariaDB (10.x, 11.x).
- Industrial Strength: Built-in automatic reconnection, position tracking, and checksum negotiation.
- Pure Go: Zero external C-library dependencies.
- Smart Parsing: Automatically extracts Primary Key IDs (INT, BIGINT, UUID strings) from raw byte streams.
- Ready for Cloud: Easy to integrate with microservices via Redis broadcasting.
git clone <repository-url>
cd binlog
go mod tidy
go build -o mysql-slave ./cmd/mysql-slaveCopy the example configuration file:
cp config.json.example config.json| Key | Description |
|---|---|
mysql.host |
MySQL master host address |
mysql.username |
Replication user (needs REPLICATION SLAVE privileges) |
slave.server_id |
Unique ID for this slave (must not conflict with master) |
slave.start_from_current |
If true, starts from the master's latest position on startup |
redis.channel |
The Redis channel name for broadcasting events |
-
Start the broadcaster:
./mysql-slave -config config.json
-
Subscribe to events (example):
redis-cli SUBSCRIBE mysql_binlog_events
-
Sample Output Payload:
{ "ts": 1714474200, "type": "INSERT", "db": "shop_db", "table": "orders", "id": "987654", "pos": 10452331 }
This project is licensed under the MIT License.