Introduction
zero-mysql is a high-performance MySQL client library for Rust.
[dependencies]
zero-mysql = "*"
Requires Rust nightly.
Quick Start
use zero_mysql::sync::Conn;
let mut conn = Conn::new("mysql://user:password@localhost/mydb")?;
// Text protocol query
conn.query_drop("INSERT INTO users (name) VALUES ('Alice')")?;
// Prepared statement
let mut stmt = conn.prepare("SELECT * FROM users WHERE id = ?")?;
conn.exec_drop(&mut stmt, (42,))?;
// Transaction
conn.transaction(|conn, _tx| {
conn.query_drop("INSERT INTO users (name) VALUES ('Bob')")?;
Ok(())
})?;
Features
- Zero-Copy: Minimal allocations and copies in hot paths
- Zero-Allocation: Reuse buffers across queries
- Sync and Async: Both
syncandtokiomodules available - Binary Protocol: Prepared statements with automatic caching
- MariaDB Bulk Execution: Single round-trip bulk operations
- Customizable Deserialization: Process rows without intermediate allocations
Feature Flags
sync(default): Synchronous APItokio(default): Asynchronous API with Tokiosync-tls: TLS support for synchronous API (experimental)tokio-tls: TLS support for asynchronous API (experimental)
Limitations
- No Streaming: All results are fetched into memory
- Nightly Rust Required: Uses unstable features for performance