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

sql.mysql

import sql.mysql

sql does not re-export this module, so it is reached only by importing it directly.

The MySQL and MariaDB adapter.

Reach it through sql, which is what keeps a program portable:

import sql

var db = sql.open('mysql://alice:secret@localhost/app')

The module underneath is here for the parts of MySQL that have no equivalent elsewhere: the server’s own settings, the connection’s id, and which of the two servers answered.

What this adapter speaks

The client/server protocol over TCP, optionally under TLS and optionally compressed with zlib or zstd, or over a unix domain socket. A socket option names one, and so does a host beginning with a slash. TLS is neither offered nor wanted there, since nothing sits in between, and the connection counts as private, which is what decides whether a plugin may send the password itself.

A statement with no values is sent as text, which is one round trip. A statement with values is prepared, so that the values travel in the server’s binary encoding rather than being written into the SQL. Prepared statements are kept and reused, so a query run in a loop is compiled once.

Authentication

mysql_native_password, caching_sha2_password (both the cached exchange and the slower one behind it), sha256_password, mysql_clear_password and MariaDB’s client_ed25519. On a connection that is not private, the two plugins that need the password itself encrypt it to the server’s public key rather than sending it, and mysql_clear_password is refused outright.

Submodules

ModuleReached asSummary
sql.mysql.authsql.mysql.auth.*The authentication plugins a MySQL or MariaDB server can ask for.
sql.mysql.connectionsql.mysql.connection.*One open MySQL connection, as the layer above it sees one.
sql.mysql.cursorsql.mysql.cursor.*Reading a MySQL result a batch at a time.
sql.mysql.driversql.mysql.driver.*Opening MySQL and MariaDB connections: reading a connection string, establishing the socket, upgrading it to…
sql.mysql.ed25519import sql.mysql.ed25519Ed25519 signing over a key derived from a password, which is what MariaDB’s client_ed25519 authentication…
sql.mysql.errorssql.mysql.errors.*Turning MySQL’s error numbers into the shared error classes.
sql.mysql.packetssql.mysql.packets.*The MySQL packet layer: framing, sequence numbering, compression and the integer and string encodings every…
sql.mysql.protocolsql.mysql.protocol.*The MySQL client/server protocol: the handshake that opens a connection and the command exchange that runs…
sql.mysql.resultsimport sql.mysql.resultsTurning what the server answered into the shapes the shared contract asks for.
sql.mysql.schemaimport sql.mysql.schemaIntrospection for MySQL, through information_schema.
sql.mysql.statementsql.mysql.statement.*A statement compiled once on the server and run many times.
sql.mysql.typessql.mysql.types.*What MySQL’s column types mean in Zuri, in both directions and in both of the protocol’s two encodings.

Constants

DRIVER

sql.mysql.DRIVER

The driver instance sql registers for MySQL.

MARIADB_DRIVER

sql.mysql.MARIADB_DRIVER

The driver instance sql registers for MariaDB.

Functions

connect()

sql.mysql.connect(dsn) -> MySqlConnection

Opens a MySQL connection directly, without going through sql.

Anything meant to stay portable should use sql.open() instead.

Parameters

  • dsn (string|dict) — A connection string or options.

Returns MySqlConnection


2026, Richard Ore and Zuri contributors