$ show go-mysql-org/go-mysql
go-mysql is a pure-Go library for the MySQL and MariaDB ecosystem. Rather than a single application, it exposes a layered set of packages and command-line tools: a low-level packet/protocol layer, a full client connection library, a MySQL-compatible server framework, a binlog replication parser and syncer, a higher-level change-data-capture (CDC) engine called canal, a mysqldump wrapper, and a database/sql driver. The command binaries (`go-mysqlbinlog`, `go-mysqldump`, `go-canal`, `go-mysqlserver`, `go-binlogparser`) demonstrate concrete uses of the library, but the real product is the reusable code surface. The core data flow for replication is: the `replication.BinlogSyncer` connects as a MySQL replica, registers for binlog dump, receives raw binlog frames, and parses them into typed events (`RowsEvent`, `TableMapEvent`, `GTIDEvent`, `QueryEvent`, etc.). The `canal` package layers on top of this by first taking a snapshot through `dump.Dumper` and then streaming subsequent binlog events through a handler interface, making it suitable for feeding downstream stores like Elasticsearch or Redis. The `client` and `server` packages implement the query side of the protocol, including authentication, prepared statements, streaming result sets, TLS, compression, and connection pooling. The `driver` package adapts this to Go's standard `database/sql` interface. The codebase is mature and heavily tested, with CI matrices covering MySQL 8.0/8.4/9.7 and MariaDB 10.11/11.4/11.8, plus fuzz test corpora for GTID and binlog decoding. It also contains notable compatibility engineering: hand-written decoders for MySQL binary JSON, decimal, `datetime2`, `time2`, GTID sets, and row events, all validated against live-server behavior. The main risks are protocol drift and manual maintenance: the error-code mapping ends around MySQL 1863, some binary resultset helpers are deprecated or inconsistent, and much of the value depends on keeping pace with new MySQL/MariaDB binlog event formats. Overall, this is a high-quality, industrially relevant library with strong reuse potential for anyone building MySQL tooling, CDC pipelines, or protocol-compatible servers in Go.
The LLM identified 4 files worth highlighting for reuse:
Decodes MySQL's internal binary JSON format into structured Go values and renders it into MySQL-compatible text form. This is a self-contained, non-obvious binary format decoder with careful handling of type tags, large objects, floating-point trailing zeros, and MySQL-specific rendering quirks. It is backed by pinned parity vectors and live-server tests, making it a trustworthy component to extract for any tool that needs to read or compare MySQL JSON values from binlogs or replicated data.
Implements encoding, decoding, parsing, merging, and comparison of MySQL GTID sets, including interval sets and tagged GTIDs. The logic is mathematically precise and independent of the rest of the library except for simple MySQL constants and errors. This is a clean, reusable data structure for systems that track replication positions or need to reason about transaction sets in a MySQL-compatible way.
Contains compact binary decoders and formatters for MySQL's `DATETIME2`, `TIMESTAMP2`, and `TIME2` binlog types. These formats are packed with fractional-second precision and signed offsets, and decoding them correctly requires deep knowledge of MySQL internals. The functions are small, deterministic, and largely self-contained, making them a reusable reference implementation for any project that needs to interpret MySQL row-based binlog data without pulling in the entire go-mysql stack.
Provides the low-level MySQL packet reader/writer with sequence-number tracking, read/write buffering, and support for zlib/zstd compressed frames. It encapsulates the tricky state machine of MySQL compressed packets, including verbatim frames, and handles flush-before-read to avoid protocol deadlocks. This is a well-isolated transport primitive that could be reused in other MySQL protocol implementations or proxy layers with minimal modification.