§reference

MariaDB

Close enough to MySQL to share a driver, and where it is not: MariaDB has a uuid type, has RETURNING on inserts, and its default login does not need TLS. The rest of the MySQL page applies.

Quick reference

dialectDialect::MariaDb
driversqlx’s MySQL driver
urlmysql://host:3306/db with Dialect::MariaDb; in a config file jdbc:mariadb://host:3306/db
loginusername and password, never in the url
uuidUUID, native (10.7 and later); CHAR(36) CHARACTER SET ascii works too
jsonJSON
timestampsDATETIME(6), holding UTC
RETURNINGon inserts, yes; on updates, no
keyed lockSqlKeyedLockProvider: GET_LOCK, server-wide names
migration lockGET_LOCK, named after the database
TLSused when the server offers it (sslmode=preferred); MariaDB 11.8 offers it by default
tested againstmariadb:11.8

The URL scheme is MySQL’s. sqlx reads MariaDB through its MySQL driver, so in code the URL is mysql://... and the dialect says MariaDB. A config file’s jdbc:mariadb:// (or mariadb://) URL sets both for you. Use Dialect::MariaDb, not MySql: the framework writes some statements differently for it.

Migration order

As on MySQL: eventlog is a database of its own, one per server, created by the first migration on your login’s connection.

migrations/
  V0000__create_eventlog_database.sql   # CREATE DATABASE IF NOT EXISTS eventlog;
  V0001__eventlog.sql                   # eventlog.events + eventlog.event_notifications + indexes
  V0002__scheduled_tasks.sql            # only with distributed jobs or the local event handler
  V0003__wallets.sql                    # your own tables

The login needs the right to create eventlog and use it; the examples grant it in an init.sql, as on MySQL. Two shards on one server would share eventlog: give each its own server.

Copy the framework’s files from wallet-example/migrations/mariadb.

Your own tables

columntyperole
idUUID PRIMARY KEYread as ekbatan::DbUuid
versionBIGINT NOT NULLoptimistic locking
stateVARCHAR(24) NOT NULLDELETED marks a soft-deleted row
created_dateDATETIME(6) NOT NULLUTC, from the model
updated_dateDATETIME(6) NOT NULLUTC, from the model

From these, schemagen writes the same module as from PostgreSQL’s and MySQL’s tables.

Where MariaDB differs from MySQL

A uuid type. MariaDB’s UUID stores 16 bytes and reads back as the usual hyphenated text; DbUuid reads it, and schemagen maps it to DbUuid whatever the column is called. The framework writes uuids to it as text, which MariaDB accepts. The examples’ MariaDB migrations use it.

RETURNING on inserts. add gives back the row as MariaDB stored it, as on PostgreSQL. update has no RETURNING on MariaDB, so it gives back the model’s next version, as on MySQL.

The default login does not need TLS. MariaDB’s default login method is not MySQL 8.4’s caching_sha2_password, so a password login works with or without TLS. MariaDB 11.8 sets up TLS for itself, and sqlx uses it when offered. Tested (wallet-example/tests/tls.rs).

Shared with MySQL

Everything else on the MySQL page applies:

See also