Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

zhenruyan/mysql-slave

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

MySQL Binlog Real-time Broadcaster

License Go Version

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.

🚀 Key Features

  • 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.

📦 Installation

git clone <repository-url>
cd binlog
go mod tidy
go build -o mysql-slave ./cmd/mysql-slave

⚙️ Configuration

Copy the example configuration file:

cp config.json.example config.json

Configuration Parameters

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

🛠 Usage

  1. Start the broadcaster:

    ./mysql-slave -config config.json
  2. Subscribe to events (example):

    redis-cli SUBSCRIBE mysql_binlog_events
  3. Sample Output Payload:

    {
     "ts": 1714474200,
     "type": "INSERT",
     "db": "shop_db",
     "table": "orders",
     "id": "987654",
     "pos": 10452331
    }

📄 License

This project is licensed under the MIT License.

About

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. / 这是一个生产级的 MySQL/MariaDB 从库模拟器。

Topics

Resources

License

Stars

Watchers

Forks

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /