Skip to main content

Crate sqlmodel_mysql

Crate sqlmodel_mysql 

Source
Expand description

MySQL driver for SQLModel Rust.

sqlmodel-mysql is the MySQL driver for the SQLModel ecosystem. It implements the MySQL wire protocol from scratch using asupersync’s TCP primitives and exposes a Connection implementation for query execution.

§Role In The Architecture

  • Implements sqlmodel-core::Connection for MySQL
  • Provides authentication, protocol framing, and type conversions
  • Powers sqlmodel-query execution and sqlmodel-session persistence

This crate implements the MySQL wire protocol from scratch using asupersync’s TCP primitives. It provides:

  • Packet framing with sequence numbers
  • Authentication (mysql_native_password, caching_sha2_password)
  • Text and binary query protocols
  • Prepared statement support
  • Connection management with state machine
  • Type conversion between Rust and MySQL types

§MySQL Protocol Overview

MySQL uses a packet-based protocol with:

  • 3-byte payload length + 1-byte sequence number header
  • Packets over 16MB are split
  • Request/response pairing via sequence numbers

§Example

use sqlmodel_mysql::{MySqlConfig, MySqlConnection};

let config = MySqlConfig::new()
    .host("localhost")
    .port(3306)
    .user("root")
    .database("mydb");

let conn = MySqlConnection::connect(config)?;

Re-exports§

pub use async_connection::MySqlAsyncConnection;
pub use async_connection::SharedMySqlConnection;
pub use config::MySqlConfig;
pub use config::SslMode;
pub use config::TlsConfig;
pub use connection::ConnectionState;
pub use connection::MySqlConnection;

Modules§

async_connection
Async MySQL connection implementation.
auth
MySQL authentication implementations.
config
MySQL connection configuration.
connection
MySQL connection implementation.
protocol
MySQL wire protocol implementation.
tls
TLS/SSL support for MySQL connections.
types
MySQL type system and type conversion.