Skip to content

Commit eb413ec

Browse files
added rust connector documentation draft
1 parent c6c1194 commit eb413ec

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

connectors/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@
268268
* [PHP](other/mariadb-php-connectors-guide.md)
269269
* [RMariaDB: MariaDB Driver for R](other/rmariadb.md)
270270
* [Ruby](other/mariadb-connector-ruby-guide.md)
271+
* [Rust](other/mariadb-rust-connector-guide.md)
271272
* [LangChain MariaDB](other/langchain-mariadb/README.md)
272273
* [API Reference](other/langchain-mariadb/api-reference/README.md)
273274
* [Vector Stores](other/langchain-mariadb/api-reference/vectorstores.md)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
description: >-
3+
The Rust connector for MariaDB provides two community-maintained crates for
4+
building native Rust applications that connect to MariaDB databases, with
5+
MariaDB-specific features contributed directly by MariaDB.
6+
icon: link
7+
---
8+
9+
# Rust Connector for MariaDB
10+
11+
## Overview
12+
13+
Rust applications can connect to MariaDB using the community-maintained drivers from the [blackbeam](https://github.com/blackbeam) project. These are not official MariaDB connectors, but MariaDB has contributed MariaDB-specific features to them, and they are the recommended way to connect to MariaDB from Rust.
14+
15+
The Rust ecosystem has two widely used community-maintained MySQL/MariaDB client crates:
16+
17+
- **[`mysql`](https://crates.io/crates/mysql)** (`rust-mysql-simple`) — a synchronous Rust driver
18+
- **[`mysql_async`](https://crates.io/crates/mysql_async)** — an asynchronous Rust driver built on Tokio
19+
20+
Both crates share a common protocol implementation library, **[`rust_mysql_common`](https://crates.io/crates/mysql_common)**, which handles low-level MySQL/MariaDB protocol primitives, value conversion, and authentication primitives used by both drivers.
21+
22+
MariaDB recommends these Rust crates, which provide robust MySQL‑protocol compatibility and include MariaDB‑specific enhancements for first‑class client support.
23+
24+
Select the driver based on your application’s architecture: use `mysql` for blocking/synchronous I/O, or `mysql_async` for non‑blocking I/O with Tokio. Both drivers have received the same MariaDB-specific contributions for the features described below.
25+
26+
## MariaDB-Specific Contributions
27+
28+
MariaDB has contributed MariaDB‑specific features directly to these crates. The following features have been implemented and incorporated into the official releases (mysql_async v0.37.0 and the corresponding rust‑mysql‑simple version):
29+
30+
### 1. PARSEC Authentication Plugin Support
31+
32+
PARSEC (Password Authentication using Response Signed with Elliptic Curve) is a modern authentication plugin introduced in MariaDB 11.6. It uses salted passwords, PBKDF2 key derivation, and ed25519 elliptic-curve signatures to prevent replay attacks and protect credentials.
33+
34+
Both `mysql_async` and `mysql` (sync) now support PARSEC authentication natively. When connecting to a MariaDB 11.6+ server configured to use the `parsec` authentication plugin, the driver will automatically handle the PARSEC handshake without any special configuration from the application developer.
35+
36+
### 2. Bulk Execution (`COM_STMT_BULK_EXECUTE`)
37+
38+
MariaDB supports a protocol extension called `COM_STMT_BULK_EXECUTE`, enabled via the `MARIADB_CLIENT_STMT_BULK_OPERATIONS` capability flag. This allows a client to execute a previously prepared statement with multiple rows of parameters in a single network round-trip, rather than sending one execution packet per row.
39+
40+
This feature is specific to MariaDB. When the driver connects to a MariaDB server that indicates support for the `MARIADB_CLIENT_STMT_BULK_OPERATIONS` capability, bulk execution is automatically negotiated and used for batch inserts or updates.
41+
42+
The benefit is significant performance improvement for write-heavy workloads, reducing network overhead and server round-trips.
43+
44+
### 3. Metadata Skipping (`MARIADB_CLIENT_CACHE_METADATA`)
45+
46+
Since MariaDB 10.6, the server supports a binary protocol optimization where result-set column metadata is not re-sent if it has not changed between executions of a prepared statement. This is negotiated via the `MARIADB_CLIENT_CACHE_METADATA` capability.
47+
48+
Both drivers now support this optimization. When connected to MariaDB 10.6+, the driver caches the column metadata on the first execution of a prepared statement and skips receiving it on subsequent executions — reducing network payload and parsing overhead on every repeated query.
49+
50+
## Crate Reference Summary
51+
52+
| Crate | Type | Description | MariaDB Features |
53+
|---|---|---|---|
54+
| [`mysql`](https://crates.io/crates/mysql) | Sync | `rust-mysql-simple`; blocking I/O | PARSEC auth, bulk execute, metadata skip |
55+
| [`mysql_async`](https://crates.io/crates/mysql_async) | Async | Tokio-based async driver | PARSEC auth, bulk execute, metadata skip |
56+
| [`mysql_common`](https://crates.io/crates/mysql_common) | Shared | Protocol primitives, value types, auth | Used internally by both drivers |
57+
58+
> **Note:** `rust_mysql_common` is a shared dependency and does not need to be added to your `Cargo.toml` directly. It is pulled in automatically by either `mysql` or `mysql_async`.
59+
60+
## Installation
61+
62+
**Sync driver:**
63+
```toml
64+
[dependencies]
65+
mysql = "*"
66+
```
67+
68+
## MariaDB Server Version Requirements
69+
70+
| Feature | Minimum MariaDB Version |
71+
|---|---|
72+
| Metadata skipping | 10.6 |
73+
| PARSEC authentication | 11.6 |
74+
| Bulk execution (`COM_STMT_BULK_EXECUTE`) | - |
75+
76+
All features are automatically negotiated during the connection handshake based on what the server announces; no application‑side configuration is needed."
77+
78+
## See Also
79+
80+
- [`mysql_async` on crates.io](https://crates.io/crates/mysql_async)
81+
- [`mysql` (sync) on crates.io](https://crates.io/crates/mysql)
82+
- [`mysql_async`](https://github.com/blackbeam/mysql_async)
83+
- [`rust-mysql-simple`](https://github.com/blackbeam/rust-mysql-simple)
84+
- [MariaDB PARSEC Authentication Plugin documentation](https://mariadb.com/docs/server/reference/plugins/authentication-plugins/authentication-plugin-parsec)
85+
- [MDEV-19237 — Metadata skip server-side implementation](https://jira.mariadb.org/browse/MDEV-19237)

0 commit comments

Comments
 (0)