mysql (Rust)
Pure-Rust MySQL client driver with a built-in connection pool, prepared statements, and TLS support.
Repository Health
Technical Analysis
The mysql crate is a MySQL database driver implemented in pure Rust, with a built-in connection pool. It speaks both the MySQL text protocol (simple queries) and binary protocol (prepared statements with binary result sets), and requires no external C client library.
It is a mature, feature-rich driver: named parameters for prepared statements, a per-connection statement cache, a buffer pool, protocol compression, large-packet support, Unix sockets and Windows named pipes, pluggable TLS via native-tls or rustls, and auth plugins for both legacy MySQL and MySQL 8’s caching_sha2_password. It runs on macOS, Windows, and Linux.
What You Get
- A pure-Rust MySQL driver with no C client dependency
- A built-in connection pool for concurrent workloads
- Text-protocol queries and binary-protocol prepared statements
- Named parameters and a
params!macro for prepared statements - Typed row mapping into Rust structs via
FromRow/FromValue - Pluggable TLS (native-tls or rustls) and MySQL 8 auth plugin support
Common Use Cases
- Connecting Rust web services and backends to MySQL or MariaDB
- Pooling database connections for concurrent request handling
- Running prepared statements with named parameters safely
- Streaming query results directly into typed Rust structs
- Connecting over TLS to managed MySQL 8 databases using caching_sha2_password
Under The Hood
Architecture — The crate implements the MySQL client protocol from scratch in Rust under src/, exposing a Pool of reusable connections plus a Conn type for single connections. It supports both the text protocol (simple query calls) and the binary protocol (prepared statements via prep/exec), with a per-connection statement cache and a buffer pool to cut allocations. Result-set rows are decoded into a Value enum and mapped to Rust types through FromRow/FromValue traits; named parameters are rewritten into positional ones before execution.
Tech Stack — Pure Rust (edition 2021) with no C client dependency. TLS is pluggable via native-tls or rustls behind feature flags, and the crate offers a rich feature matrix (minimal, derive, buffer-pool, compression) so consumers compile only what they need. It supports Unix sockets, Windows named pipes, protocol compression, and large packets, and builds via a build.rs script.
Code Quality — A mature, long-lived driver (version 28) with a dedicated tests/ directory and CI on Azure Pipelines across macOS, Windows, and Linux. Recent development activity is low, consistent with a stable, feature-complete driver rather than one in flux.
API Design — The public API is compact and ergonomic: get a Pool, grab a connection, and call query, exec, or the query_map/exec_map helpers that stream rows into typed structs. Named parameters and the params! macro reduce boilerplate for prepared statements, and thorough docs.rs documentation with inline examples smooth adoption.