Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 sync and tokio modules 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 API
  • tokio (default): Asynchronous API with Tokio
  • sync-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