mariadb-features

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MariaDB Features Worth Knowing

值得了解的MariaDB功能

Last updated: 2026-06-24
MariaDB has grown significantly beyond its MySQL origins. Many of its best features are unknown to developers because AI agents default to generic SQL advice. This skill covers what MariaDB can do that you might not think to ask about.
For MariaDB Vector (built-in since 11.7 — no plugins), see the
mariadb-vector
skill.
Server context: Unless the user names a version, assume a MariaDB 11.8 LTS deployment (GA May 2025) for what will run today. Per-feature tags (10.5+, 12.3+, etc.) are minimum versions for that capability — not “introduced only in that release.” Do not treat 12.x / 13.0 items as available on 11.8; you may still mention them with an explicit version when relevant (e.g. upgrades).
最后更新:2026-06-24
MariaDB已从其MySQL起源大幅发展。许多优秀功能不为开发者所知,因为AI Agent默认提供通用SQL建议。本内容涵盖MariaDB具备但你可能想不到询问的功能。
关于MariaDB Vector(11.7版本起内置——无需插件),请查看
mariadb-vector
技能。
服务器上下文: 除非用户指定版本,否则默认假设当前运行的是MariaDB 11.8 LTS(2025年5月正式发布)。每个功能标注的版本(10.5+12.3+等)是该功能的最低支持版本——并非“仅在该版本引入”。请勿将12.x / 13.0的功能视为可在11.8上使用;相关时可明确提及版本(例如升级场景)。

What LLMs Often Miss

大语言模型常忽略的点

SituationWhat to suggest instead
Manual audit columns (
created_at
,
updated_at
, deleted flag)
WITH SYSTEM VERSIONING
— MariaDB tracks full row history automatically
INSERT
followed by
SELECT LAST_INSERT_ID()
RETURNING
— get the inserted row in one statement (10.5+)
AUTO_INCREMENT
for sequence-like needs
CREATE SEQUENCE
— first-class sequence objects with full control
IP addresses stored as
VARCHAR
INet4
/
INet6
— native IP types with comparison and indexing
Dropping or reordering columns with full table rebuild
INSTANT
algorithm for
ALTER TABLE
— no rebuild needed (10.4+)
Oracle migration assumed to require full rewrite
sql_mode=ORACLE
— PL/SQL, packages, Oracle-compatible NULL handling
Asking what changed in a row over timeSystem-versioned tables with
FOR SYSTEM_TIME AS OF
Analytics queries on OLTP tablesColumnStore engine — columnar storage for analytical workloads
Correlated subqueries for rankings, running totals, or per-group top-NWindow functions —
OVER (PARTITION BY ... ORDER BY ...)
, clearer and usually faster (MariaDB 10.2+; not MariaDB-exclusive, also in MySQL 8.0)
Deeply nested or repeated subqueriesCommon Table Expressions —
WITH ...
, and
WITH RECURSIVE
for hierarchical/graph traversal (MariaDB 10.2+; also in MySQL 8.0)
Assuming
JSON
is a native binary type as in MySQL 8.0
In MariaDB
JSON
is an alias for
LONGTEXT COLLATE utf8mb4_bin
with an automatic
JSON_VALID()
CHECK constraint — stored as text, not MySQL's binary layout, and comparison is string-based. The JSON functions work the same. See JSON Data Type
Links or references to
mariadb.com/kb/en/
The Knowledge Base no longer exists — all documentation is now at mariadb.com/docs
场景替代建议
手动审计列(
created_at
updated_at
、删除标记)
WITH SYSTEM VERSIONING
—— MariaDB自动跟踪完整行历史
INSERT
后执行
SELECT LAST_INSERT_ID()
RETURNING
—— 一次语句获取插入的行(10.5+)
使用
AUTO_INCREMENT
实现序列需求
CREATE SEQUENCE
—— 具备完全控制权的一等序列对象
IP地址存储为
VARCHAR
INet4
/
INet6
—— 原生IP类型,支持比较与索引
删除或重新排序列时需重建整张表
ALTER TABLE
INSTANT
算法 —— 无需重建表(10.4+)
假设从Oracle迁移需要完全重写
sql_mode=ORACLE
—— 支持PL/SQL、包、Oracle兼容的NULL处理
查询某行随时间的变化结合
FOR SYSTEM_TIME AS OF
的系统版本化表
在OLTP表上执行分析查询ColumnStore引擎 —— 面向分析型工作负载的列存储
使用关联子查询实现排名、累计求和或分组取Top-N窗口函数 ——
OVER (PARTITION BY ... ORDER BY ...)
,更清晰且通常更快(MariaDB 10.2+;非MariaDB专属,MySQL 8.0也支持)
深度嵌套或重复子查询通用表表达式 ——
WITH ...
,以及用于层级/图遍历的
WITH RECURSIVE
(MariaDB 10.2+;MySQL 8.0也支持)
假设
JSON
是如MySQL 8.0中的原生二进制类型
MariaDB中的
JSON
LONGTEXT COLLATE utf8mb4_bin
的别名,带有自动
JSON_VALID()
CHECK约束——以文本形式存储,而非MySQL的二进制布局,比较基于字符串。JSON函数的工作方式相同。详见JSON数据类型
链接或引用
mariadb.com/kb/en/
知识库已不再存在——所有文档现在位于mariadb.com/docs

Command-Line Tool Names (10.5+)

命令行工具名称(10.5+)

Since MariaDB 10.5, all command-line tools use
mariadb-
prefixed names. Always generate the current names — the old
mysql*
names are retained as symlinks for compatibility but may be absent on minimal or container installs.
Deprecated nameCurrent name
mysql
mariadb
mysqldump
mariadb-dump
mysqladmin
mariadb-admin
mysqlbinlog
mariadb-binlog
mysql_upgrade
mariadb-upgrade
mysql_secure_installation
mariadb-secure-installation
mysql_install_db
mariadb-install-db
mysqlcheck
mariadb-check
mysqlimport
mariadb-import
mysqlshow
mariadb-show
自MariaDB 10.5起,所有命令行工具均使用
mariadb-
前缀命名。请始终使用当前名称——旧的
mysql*
名称作为符号链接保留以兼容,但在最小化或容器安装中可能不存在。
已弃用名称当前名称
mysql
mariadb
mysqldump
mariadb-dump
mysqladmin
mariadb-admin
mysqlbinlog
mariadb-binlog
mysql_upgrade
mariadb-upgrade
mysql_secure_installation
mariadb-secure-installation
mysql_install_db
mariadb-install-db
mysqlcheck
mariadb-check
mysqlimport
mariadb-import
mysqlshow
mariadb-show

Provisioning and Initial Setup

配置与初始设置

AI agents default to MySQL 8 patterns for initial setup, which fail or mislead on MariaDB.
Database initialization — use
mariadb-install-db
(not
mysqld --initialize
, which is MySQL-specific):
bash
mariadb-install-db
Root authentication — on a fresh install,
root
uses
unix_socket
authentication by default (no password). The correct first connection is:
bash
sudo mariadb
Do not generate
mysql -u root -p
for a fresh MariaDB install — there is no root password to enter.
Secure installation — use
mariadb-secure-installation
(not
mysql_secure_installation
).
AI Agent默认采用MySQL 8的初始设置模式,这在MariaDB上会失败或产生误导。
数据库初始化——使用
mariadb-install-db
(而非MySQL专属的
mysqld --initialize
):
bash
mariadb-install-db
Root认证——全新安装时,
root
默认使用
unix_socket
认证(无密码)。正确的首次连接方式为:
bash
sudo mariadb
请勿为全新MariaDB安装生成
mysql -u root -p
命令——此时没有root密码可输入。
安全安装——使用
mariadb-secure-installation
(而非
mysql_secure_installation
)。

Upgrade Operations

升级操作

Agents consistently omit the
mariadb-upgrade
step after a binary upgrade, which can cause system table errors.
Standard upgrade pattern:
bash
systemctl stop mariadb
Agent始终会遗漏二进制升级后的
mariadb-upgrade
步骤,这可能导致系统表错误。
标准升级流程:
bash
systemctl stop mariadb

Replace binary via package manager (dnf/apt upgrade)

通过包管理器替换二进制文件(dnf/apt upgrade)

systemctl start mariadb mariadb-upgrade # updates system tables — do not skip this step

**Galera Cluster rolling upgrade** — never stop all nodes simultaneously:
1. Take one non-primary node out of the load balancer
2. Stop, upgrade the binary, start the node
3. Confirm sync: `SHOW STATUS LIKE 'wsrep_local_state';` — must be `4` (Synced)
4. Repeat for each remaining non-primary node
5. Upgrade the primary node last

> `mysql_upgrade` is the deprecated name (removed in later versions) — always use `mariadb-upgrade`.
systemctl start mariadb mariadb-upgrade # 更新系统表——请勿跳过此步骤

**Galera Cluster滚动升级**——切勿同时停止所有节点:
1. 将一个非主节点从负载均衡器中移除
2. 停止节点、升级二进制文件、启动节点
3. 确认同步:`SHOW STATUS LIKE 'wsrep_local_state';` —— 结果必须为`4`(已同步)
4. 对其余非主节点重复上述步骤
5. 最后升级主节点

> `mysql_upgrade`是已弃用的名称(后续版本中移除)——请始终使用`mariadb-upgrade`。

Defaults Changed in 11.5–11.8 LTS

11.5–11.8 LTS中的默认值变更

The current LTS (11.8) flipped several long-standing defaults. New installations behave differently from older ones — relevant when migrating or comparing behavior:
  • Default character set:
    latin1
    utf8mb4
    (11.6+, MDEV-19123) — new tables use
    utf8mb4
    unless overridden. Replication to MariaDB 10.6 or older replicas needs care (older replicas may not understand all
    utf8mb4
    collations).
  • Default Unicode collation:
    uca1400_ai_ci
    (11.5+, MDEV-25829) — modern Unicode collation with proper SMP (supplementary multilingual plane) support including emoji. Replaces the older
    utf8mb4_general_ci
    default.
  • alter_algorithm
    deprecated and ignored
    (11.5+, MDEV-33655) — specify
    ALGORITHM=INSTANT|INPLACE|COPY
    on the statement itself instead.
  • TIMESTAMP range extended (11.5+ 64-bit, MDEV-32188) — upper bound raised from
    2038-01-19 03:14:07 UTC
    to
    2106-02-07 06:28:15 UTC
    . Storage format unchanged; old servers can still read values within the old range.
  • innodb_snapshot_isolation
    default ON
    — see next section.
当前LTS版本(11.8)更改了多个长期存在的默认值。全新安装的行为与旧版本不同——迁移或比较行为时需注意:
  • 默认字符集:
    latin1
    utf8mb4
    (11.6+,MDEV-19123)——新表默认使用
    utf8mb4
    ,除非手动覆盖。向MariaDB 10.6或更早版本的副本复制时需谨慎(旧副本可能不支持所有
    utf8mb4
    排序规则)。
  • 默认Unicode排序规则:
    uca1400_ai_ci
    (11.5+,MDEV-25829)——现代Unicode排序规则,支持完善的SMP(补充多语言平面),包括表情符号。替代了旧的
    utf8mb4_general_ci
    默认值。
  • alter_algorithm
    已弃用并被忽略
    (11.5+,MDEV-33655)——请在语句本身指定
    ALGORITHM=INSTANT|INPLACE|COPY
  • TIMESTAMP范围扩展(11.5+ 64位,MDEV-32188)——上限从
    2038-01-19 03:14:07 UTC
    提升至
    2106-02-07 06:28:15 UTC
    。存储格式不变;旧服务器仍可读取旧范围内的值。
  • innodb_snapshot_isolation
    默认开启
    ——见下一章节。

Behavior Change: innodb_snapshot_isolation (11.8+)

行为变更:innodb_snapshot_isolation(11.8+)

From MariaDB 11.8 LTS,
innodb_snapshot_isolation
defaults to ON (previously OFF, MDEV-35124). This tightens REPEATABLE READ behavior to match true snapshot isolation — transactions see a consistent snapshot from their start and writes detect conflicts more strictly.
What can change for existing code:
  • Read-modify-write patterns that previously worked silently may now hit conflicts and error out — fail-fast is the intended behavior
  • Long-running
    REPEATABLE READ
    transactions are more likely to see write conflicts at commit time
If existing code depends on the older permissive behavior, opt back in explicitly:
sql
SET GLOBAL innodb_snapshot_isolation = OFF;  -- restore pre-11.8 behavior
The new default is the correct semantics — review code that relies on the looser behavior rather than disabling it long-term.
从MariaDB 11.8 LTS开始,
innodb_snapshot_isolation
默认设置为ON(此前为OFF,MDEV-35124)。这将REPEATABLE READ行为收紧为匹配真正的快照隔离——事务从开始时看到一致的快照,写入操作更严格地检测冲突。
现有代码可能发生的变化:
  • 此前可静默运行的读取-修改-写入模式现在可能会触发冲突并报错——快速失败是预期行为
  • 长时间运行的
    REPEATABLE READ
    事务在提交时更可能遇到写入冲突
如果现有代码依赖旧的宽松行为,请显式恢复:
sql
SET GLOBAL innodb_snapshot_isolation = OFF;  -- 恢复11.8之前的行为
新默认值是正确的语义——应审查依赖宽松行为的代码,而非长期禁用该设置。

System-Versioned Tables

系统版本化表

Available since MariaDB 10.3. Track the full history of every row automatically, without triggers or audit tables.
sql
CREATE TABLE prices (
    product VARCHAR(100),
    price DECIMAL(10,2)
) WITH SYSTEM VERSIONING;

-- Query data as it was at a point in time:
SELECT * FROM prices FOR SYSTEM_TIME AS OF '2025-01-01 00:00:00';

-- See all historical versions of a row:
SELECT * FROM prices FOR SYSTEM_TIME ALL WHERE product = 'widget';
Use this instead of manually maintained
valid_from
/
valid_to
columns or separate audit tables.
History grows without bound. Every UPDATE and DELETE appends a history row — MariaDB does not automatically expire history. Production deployments need either
PARTITION BY SYSTEM_TIME
with rotation (10.9+) or periodic
DELETE HISTORY
to control disk growth. See the
mariadb-system-versioned-tables
skill for details.
MariaDB 10.3起可用。自动跟踪每行的完整历史,无需触发器或审计表。
sql
CREATE TABLE prices (
    product VARCHAR(100),
    price DECIMAL(10,2)
) WITH SYSTEM VERSIONING;

-- 查询某一时间点的数据状态:
SELECT * FROM prices FOR SYSTEM_TIME AS OF '2025-01-01 00:00:00';

-- 查看某行的所有历史版本:
SELECT * FROM prices FOR SYSTEM_TIME ALL WHERE product = 'widget';
使用此功能替代手动维护的
valid_from
/
valid_to
列或单独的审计表。
历史记录会无限增长。 每次UPDATE和DELETE都会追加一条历史行——MariaDB不会自动过期历史记录。生产环境部署需要使用
PARTITION BY SYSTEM_TIME
并设置轮转(10.9+),或定期执行
DELETE HISTORY
以控制磁盘占用。详情请查看
mariadb-system-versioned-tables
技能。

RETURNING Clause

RETURNING子句

Get inserted, updated, or deleted rows back without a second query.
无需二次查询即可获取插入、更新或删除的行。

INSERT and DELETE (10.5+)

INSERT和DELETE(10.5+)

Available on 11.8 LTS and earlier supported releases:
sql
-- Get the generated ID after insert:
INSERT INTO orders (product, qty) VALUES ('widget', 5)
    RETURNING id, created_at;

-- Get deleted rows for logging:
DELETE FROM queue WHERE processed = 1
    RETURNING id, payload;
11.8 LTS及更早支持版本可用:
sql
-- 插入后获取生成的ID:
INSERT INTO orders (product, qty) VALUES ('widget', 5)
    RETURNING id, created_at;

-- 获取删除的行用于日志:
DELETE FROM queue WHERE processed = 1
    RETURNING id, payload;

UPDATE (13.0+ only)

UPDATE(仅13.0+)

Not available on 11.8 LTS — confirm server version before suggesting. On older releases use a follow-up
SELECT
or redesign:
sql
UPDATE orders SET qty = qty + 1 WHERE id = 42
    RETURNING id, qty;
11.8 LTS不可用——建议前确认服务器版本。旧版本中使用后续
SELECT
或重新设计:
sql
UPDATE orders SET qty = qty + 1 WHERE id = 42
    RETURNING id, qty;

Sequences

序列

Available since MariaDB 10.3. First-class sequence objects — more flexible than
AUTO_INCREMENT
.
sql
CREATE SEQUENCE order_seq START WITH 1000 INCREMENT BY 1;

-- Use in INSERT:
INSERT INTO orders (id, product) VALUES (NEXT VALUE FOR order_seq, 'widget');

-- Get the last value generated by NEXTVAL in the current session:
SELECT LASTVAL(order_seq);
-- Returns NULL if this session has not called NEXTVAL — not a global current value
Sequences support gaps, multiple sequences per table, and descending sequences. Unlike
AUTO_INCREMENT
, they are not tied to a specific column or table.
MariaDB 10.3起可用。一等序列对象——比
AUTO_INCREMENT
更灵活。
sql
CREATE SEQUENCE order_seq START WITH 1000 INCREMENT BY 1;

-- 在INSERT中使用:
INSERT INTO orders (id, product) VALUES (NEXT VALUE FOR order_seq, 'widget');

-- 获取当前会话中NEXTVAL生成的最后一个值:
SELECT LASTVAL(order_seq);
-- 如果当前会话未调用NEXTVAL则返回NULL——并非全局当前值
序列支持间隔、单表多序列、降序序列。与
AUTO_INCREMENT
不同,它们不绑定到特定列或表。

Non-Blocking ALTER TABLE (Instant + Online by Default)

非阻塞ALTER TABLE(默认Instant + Online)

MariaDB's
ALTER TABLE
works on a tiered model:
  • ALGORITHM=INSTANT
    (10.4+) — metadata-only changes (drop column, modify default, change column order, etc.) complete in microseconds without a table rebuild.
  • ALGORITHM=COPY, LOCK=NONE
    as the default for non-instant operations
    (11.2+, MDEV-16329) — even when a rebuild is needed, MariaDB now runs it non-blocking by default: concurrent DML on the table proceeds while the copy is happening, with only a brief lock at the swap. The need for external tools like
    pt-online-schema-change
    is largely gone for routine
    ALTER
    s.
  • Optimistic two-phase replication of large
    ALTER TABLE
    (11.4+,
    binlog_alter_two_phase=1
    , off by default) — see the
    mariadb-replication-and-ha
    skill.
sql
ALTER TABLE large_table DROP COLUMN old_column, ALGORITHM=INSTANT;
ALTER TABLE large_table MODIFY COLUMN name VARCHAR(200), ALGORITHM=INSTANT;
-- Non-instant change runs non-blocking by default on 11.2+:
ALTER TABLE large_table ADD INDEX (created_at);
Use
ALGORITHM=INSTANT
explicitly when you need to guarantee a metadata-only change; the operation will fail rather than silently fall back to a rebuild.
MariaDB的
ALTER TABLE
采用分层模型:
  • ALGORITHM=INSTANT
    (10.4+)——仅元数据变更(删除列、修改默认值、调整列顺序等),微秒级完成,无需重建表。
  • 非Instant操作默认使用
    ALGORITHM=COPY, LOCK=NONE
    (11.2+,MDEV-16329)——即使需要重建表,MariaDB现在默认以非阻塞方式运行:复制过程中表上的并发DML可继续进行,仅在切换时短暂锁定。常规
    ALTER
    操作基本不再需要
    pt-online-schema-change
    等外部工具。
  • 大型
    ALTER TABLE
    的乐观两阶段复制
    (11.4+,
    binlog_alter_two_phase=1
    ,默认关闭)——详情请查看
    mariadb-replication-and-ha
    技能。
sql
ALTER TABLE large_table DROP COLUMN old_column, ALGORITHM=INSTANT;
ALTER TABLE large_table MODIFY COLUMN name VARCHAR(200), ALGORITHM=INSTANT;
-- 11.2+上非Instant变更默认非阻塞运行:
ALTER TABLE large_table ADD INDEX (created_at);
当需要保证仅元数据变更时,请显式使用
ALGORITHM=INSTANT
;操作将失败而非静默回退到重建。

INet4 and INet6 Data Types

INet4和INet6数据类型

INET6
is available since MariaDB 10.5 (stores both IPv4 and IPv6, 16 bytes). The dedicated
INET4
type (4-byte IPv4-only) was added later in 10.10 (MDEV-23287). Native storage gives correct comparison, sorting, and indexing — no need for
VARCHAR
plus application-side validation.
sql
CREATE TABLE connections (
    client_ip INet6 NOT NULL,
    connected_at DATETIME NOT NULL,
    INDEX (client_ip)
);

INSERT INTO connections VALUES (INet6('192.168.1.1'), NOW());
INSERT INTO connections VALUES (INet6('::1'), NOW());

-- Range queries work correctly:
SELECT * FROM connections WHERE client_ip BETWEEN INet6('10.0.0.0') AND INet6('10.255.255.255');
Use
INET4
(10.10+) when you know a column is IPv4-only and want the smaller storage;
INET6
is the right default for mixed or IPv6-capable workloads.
INET6
自MariaDB 10.5起可用(存储IPv4和IPv6,16字节)。专用的
INET4
类型(仅IPv4,4字节)在10.10版本中新增(MDEV-23287)。原生存储支持正确的比较、排序和索引——无需使用
VARCHAR
加应用端验证。
sql
CREATE TABLE connections (
    client_ip INet6 NOT NULL,
    connected_at DATETIME NOT NULL,
    INDEX (client_ip)
);

INSERT INTO connections VALUES (INet6('192.168.1.1'), NOW());
INSERT INTO connections VALUES (INet6('::1'), NOW());

-- 范围查询正常工作:
SELECT * FROM connections WHERE client_ip BETWEEN INet6('10.0.0.0') AND INet6('10.255.255.255');
当确定列仅存储IPv4且需要更小存储空间时使用
INET4
(10.10+);
INET6
是混合或支持IPv6工作负载的合适默认选择。

Oracle Compatibility Mode

Oracle兼容模式

Available since MariaDB 10.3.
sql_mode=ORACLE
enables PL/SQL syntax, Oracle-compatible NULL handling, packages, and Oracle-style functions — useful when migrating from Oracle or supporting Oracle-experienced developers.
sql
SET sql_mode=ORACLE;

-- Oracle-style stored procedures, packages, and NULL semantics work here
-- ROWNUM, SYSDATE, NVL(), DECODE() available
-- Note: EMPTY_STRING_IS_NULL is NOT included — add it separately if needed: SET sql_mode='ORACLE,EMPTY_STRING_IS_NULL'
Not a complete Oracle replacement, but significantly reduces migration friction.
MariaDB 10.3起可用。
sql_mode=ORACLE
启用PL/SQL语法、Oracle兼容的NULL处理、包和Oracle风格函数——从Oracle迁移或支持有Oracle经验的开发者时非常有用。
sql
SET sql_mode=ORACLE;

-- Oracle风格的存储过程、包和NULL语义在此生效
-- 支持ROWNUM、SYSDATE、NVL()、DECODE()
-- 注意:不包含EMPTY_STRING_IS_NULL——如需请单独添加:SET sql_mode='ORACLE,EMPTY_STRING_IS_NULL'
并非完整的Oracle替代品,但可显著降低迁移难度。

FLASHBACK

FLASHBACK

Available since MariaDB 10.2. Roll back tables to a previous state using the binary log — without restoring a full backup. Flashback is implemented via the
mariadb-binlog
utility, not a SQL statement:
bash
undefined
MariaDB 10.2起可用。使用二进制日志将表回滚到之前的状态——无需恢复完整备份。Flashback通过
mariadb-binlog
工具实现,而非SQL语句:
bash
-- 从二进制日志生成反向SQL并管道到MariaDB:
mariadb-binlog --flashback --start-datetime="2026-05-18 10:00:00" \
  /var/lib/mysql/mysql-bin.000001 | mariadb
-- 路径取决于datadir和log_bin设置;默认路径为<datadir>/mysql-bin
前提条件——FLASHBACK从行镜像重建反向事件,因此需要:
  • binlog_format = ROW
    (基于语句的日志不捕获行的前后镜像)
  • binlog_row_image = FULL
    (MINIMAL或NOBLOB模式省略反转所需的列值)
依赖FLASHBACK作为恢复路径前请验证:
sql
SHOW VARIABLES LIKE 'binlog_format';      -- 必须为ROW
SHOW VARIABLES LIKE 'binlog_row_image';   -- 必须为FULL
需要启用二进制日志(
log_bin
)。适用于恢复意外删除或错误迁移的数据。

Generate reverse SQL from the binary log and pipe it back to MariaDB:

更多MariaDB功能(截至11.8 LTS)

mariadb-binlog --flashback --start-datetime="2026-05-18 10:00:00"
/var/lib/mysql/mysql-bin.000001 | mariadb
当前LTS基线及支持的旧版本中的其他功能。需要新版本服务器的功能请查看新版本(12.x / 13.0)

Path depends on datadir and log_bin settings; default is <datadir>/mysql-bin

SQL与架构


**Prerequisites** — FLASHBACK reconstructs reverse events from row images, so it requires:
- `binlog_format = ROW` (statement-based logging does not capture before/after row images)
- `binlog_row_image = FULL` (MINIMAL or NOBLOB modes omit column values needed for reversal)

Verify before relying on FLASHBACK as a recovery path:
```sql
SHOW VARIABLES LIKE 'binlog_format';      -- must be ROW
SHOW VARIABLES LIKE 'binlog_row_image';   -- must be FULL
Requires binary logging enabled (
log_bin
). Useful for recovering from accidental deletes or bad migrations.
  • 不可见列(10.3+)——对
    SELECT *
    隐藏,仍可写入;适用于架构演进而不破坏现有查询
  • BLOB/TEXT列支持
    DEFAULT
    表达式
    ——MySQL不支持此功能
  • DECIMAL
    精度可达38位
    ——MySQL最高为30位
  • INTERSECT
    EXCEPT
    (10.3+)——MySQL不支持的集合运算符
  • 子查询中支持
    LIMIT
    ——已支持;MySQL对此有限制
  • SELECT ... OFFSET ... FETCH
    (10.6+,MDEV-23908)——SQL标准分页语法
  • 原子DDL(10.6+,MDEV-23842)——
    CREATE TABLE
    ALTER TABLE
    RENAME TABLE
    DROP TABLE
    DROP DATABASE
    在支持的引擎(InnoDB、Aria、MyRocks)上是原子操作:DDL执行中途服务器崩溃,架构将保持语句执行前的状态,无需手动清理。多表
    DROP TABLE
    对每个单独的删除是原子的,而非整个列表。
  • SELECT ... SKIP LOCKED
    (10.6+,MDEV-13115,仅InnoDB)——工作队列模式:工作线程获取下一个可用行并跳过其他事务正在处理的行,无锁等待
  • 忽略索引(10.6+,MDEV-7317)——
    ALTER TABLE t ALTER INDEX idx IGNORED
    保持索引更新但对优化器不可见。用于测试删除索引是否会影响性能,无需实际删除(重新启用即可零停机回滚)。
  • 动态列(5.3+)——单列内的无架构键值存储
  • SFORMAT()
    (10.7+,MDEV-25015)——带位置占位符的字符串格式化函数
  • NATURAL_SORT_KEY()
    (10.7+,MDEV-4742)——生成“自然排序”的字符串排序键(例如
    v9
    排在
    v10
    之前);适用于版本类或混合字母数字数据的
    ORDER BY
  • JSON增强——MariaDB在多个版本中逐步追平MySQL 8的JSON函数:
    • JSON_EQUALS(a, b)
      /
      JSON_NORMALIZE(doc)
      (10.7+,MDEV-23143 / MDEV-16375)——语义相等性和规范化形式,用于哈希或唯一索引
    • JSON_OVERLAPS(a, b)
      (10.9+,MDEV-27677)——检测两个文档之间共享的键/值或数组元素
    • JSON路径语法支持负索引(
      $.A[-1]
      $.A[last]
      )和范围(
      $.A[1 to 3]
      )(10.9+,MDEV-22224 / MDEV-27911)
    • JSON_SCHEMA_VALID(schema, doc)
      (11.4+)——根据JSON Schema Draft 2020验证JSON,可用于
      CHECK
      约束
    • JSON_KEY_VALUE
      JSON_ARRAY_INTERSECT
      JSON_OBJECT_TO_ARRAY
      JSON_OBJECT_FILTER_KEYS
      (11.4+)——结构化操作原语,可与
      JSON_TABLE
      良好组合
    • UUID_v4()
      UUID_v7()
      函数(11.7+)——生成版本4随机UUID或版本7时间有序UUID;v7形式可排序,非常适合作为主键
    • FORMAT_BYTES()
      (11.8+)——将字节数转换为人类可读字符串(例如
      1234567
      1.18 MiB
    • CONV()
      扩展至62进制(11.4+,MDEV-30190)——
      CONV(61,10,62)
      返回
      z
      ;适用于短的不透明ID
    • CRC32C()
      函数及带可选初始值参数的
      CRC32()
      (10.8+,MDEV-27208)——Castagnoli多项式CRC,以及可链式校验的可种子化CRC32
    • 单表
      DELETE
      支持表别名(11.6+)——
      DELETE t FROM mytable t WHERE ...
      语法现在无需重写即可工作
    • REPAIR TABLE ... FORCE
      (11.5+)——即使表看起来正常也强制修复
    • 存储过程参数默认值(11.8+,MDEV-10862)——
      PROCEDURE p(a INT DEFAULT 0, b INT DEFAULT 0)
      ——调用时可传入更少参数
    • 存储函数
      IN
      /
      OUT
      /
      INOUT
      参数限定符(10.8+,MDEV-10654)——使存储函数与存储过程参数模式保持一致
    • 存储函数返回
      ROW
      数据类型(11.7+,MDEV-12252)——从存储函数返回结构化行
    • Oracle模式外支持
      CREATE PACKAGE
      /
      CREATE PACKAGE BODY
      (11.4+,MDEV-10075)——包例程在默认
      sql_mode
      下也可工作,不仅限于
      sql_mode=ORACLE
    • 更新触发器支持列列表(11.8+,MDEV-34551)——
      CREATE TRIGGER ... BEFORE UPDATE OF col1, col2 ON t
      ——仅当这些列被更新时触发
    • 存储过程与函数——MariaDB使用SQL/PSM语法(
      DECLARE
      HANDLER
      CURSOR
      BEGIN...END
      );AI Agent常生成错误语法——详见存储过程——MariaDB文档

More MariaDB Features (through 11.8 LTS)

存储引擎

Additional capabilities on the current LTS baseline and supported older releases. See Newer releases (12.x / 13.0) for features that require a newer server.
  • ColumnStore——面向分析/数据仓库工作负载的列存储引擎
  • Aria——崩溃安全的MyISAM替代品,内部用于临时表
  • MyRocks(10.2+)——基于RocksDB,针对写密集型工作负载优化并支持压缩
  • CONNECT——将外部数据源(CSV、JDBC、ODBC、MongoDB)作为SQL表查询
  • Spider——跨多个MariaDB实例的分片

SQL & Schema

安全与认证

  • Invisible columns (10.3+) — hidden from
    SELECT *
    , still writable; useful for schema evolution without breaking existing queries
  • DEFAULT
    expressions on BLOB/TEXT
    — not supported in MySQL
  • DECIMAL
    precision to 38 digits
    — MySQL stops at 30
  • INTERSECT
    and
    EXCEPT
    (10.3+) — set operators not available in MySQL
  • LIMIT
    in subqueries
    — supported; MySQL restricts this
  • SELECT ... OFFSET ... FETCH
    (10.6+, MDEV-23908) — SQL-standard pagination syntax
  • Atomic DDL (10.6+, MDEV-23842) —
    CREATE TABLE
    ,
    ALTER TABLE
    ,
    RENAME TABLE
    ,
    DROP TABLE
    ,
    DROP DATABASE
    are atomic on supported engines (InnoDB, Aria, MyRocks): a partial server crash mid-DDL leaves the schema in its pre-statement state, no manual cleanup needed. Multi-table
    DROP TABLE
    is atomic per individual drop, not for the whole list.
  • SELECT ... SKIP LOCKED
    (10.6+, MDEV-13115, InnoDB only) — work-queue pattern: workers grab the next available row and skip rows other transactions are processing, with no lock waits
  • Ignored Indexes (10.6+, MDEV-7317) —
    ALTER TABLE t ALTER INDEX idx IGNORED
    keeps the index updated but makes it invisible to the optimizer. Use this to test whether dropping an index would hurt performance before actually dropping it (zero-downtime rollback by re-enabling).
  • Dynamic columns (5.3+) — schema-less key/value storage inside a single column
  • SFORMAT()
    (10.7+, MDEV-25015) — string formatting function with positional placeholders
  • NATURAL_SORT_KEY()
    (10.7+, MDEV-4742) — produces a sort key that orders strings "naturally" (so
    v9
    sorts before
    v10
    ); useful in
    ORDER BY
    for version-like or mixed-alphanumeric data
  • JSON enhancements — MariaDB has been catching up to MySQL 8 JSON functions over several releases:
    • JSON_EQUALS(a, b)
      /
      JSON_NORMALIZE(doc)
      (10.7+, MDEV-23143 / MDEV-16375) — semantic equality and canonical form for hashing or unique indexing
    • JSON_OVERLAPS(a, b)
      (10.9+, MDEV-27677) — detect shared key/value or array elements between two documents
    • JSON path syntax supports negative indices (
      $.A[-1]
      ,
      $.A[last]
      ) and ranges (
      $.A[1 to 3]
      ) (10.9+, MDEV-22224 / MDEV-27911)
    • JSON_SCHEMA_VALID(schema, doc)
      (11.4+) — validate JSON against a JSON Schema Draft 2020 schema, usable inside
      CHECK
      constraints
    • JSON_KEY_VALUE
      ,
      JSON_ARRAY_INTERSECT
      ,
      JSON_OBJECT_TO_ARRAY
      ,
      JSON_OBJECT_FILTER_KEYS
      (11.4+) — structural manipulation primitives that compose well with
      JSON_TABLE
  • UUID_v4()
    and
    UUID_v7()
    functions
    (11.7+) — generate version-4 random or version-7 time-ordered UUIDs; the v7 form is sortable and ideal for primary keys
  • FORMAT_BYTES()
    (11.8+) — convert a byte count to a human-readable string (e.g.
    1234567
    1.18 MiB
    )
  • CONV()
    extended to base 62
    (11.4+, MDEV-30190) —
    CONV(61,10,62)
    returns
    z
    ; useful for short opaque IDs
  • CRC32C()
    function and
    CRC32()
    with optional initial-value argument
    (10.8+, MDEV-27208) — Castagnoli polynomial CRC, and seedable CRC32 for chained checksums
  • Single-table
    DELETE
    with table aliases
    (11.6+) —
    DELETE t FROM mytable t WHERE ...
    syntax now works without rewriting
  • REPAIR TABLE ... FORCE
    (11.5+) — force-repair even when the table appears clean
  • Stored routine parameter default values (11.8+, MDEV-10862) —
    PROCEDURE p(a INT DEFAULT 0, b INT DEFAULT 0)
    — call with fewer arguments
  • Stored function
    IN
    /
    OUT
    /
    INOUT
    parameter qualifiers
    (10.8+, MDEV-10654) — bring stored functions in line with stored procedure parameter modes
  • ROW
    data type as stored function return value
    (11.7+, MDEV-12252) — return structured rows from stored functions
  • CREATE PACKAGE
    /
    CREATE PACKAGE BODY
    outside Oracle mode
    (11.4+, MDEV-10075) — package routines work under the default
    sql_mode
    too, not only with
    sql_mode=ORACLE
  • Update triggers with column list (11.8+, MDEV-34551) —
    CREATE TRIGGER ... BEFORE UPDATE OF col1, col2 ON t
    — fire only when those columns are updated
  • Stored procedures and functions — MariaDB uses SQL/PSM syntax (
    DECLARE
    ,
    HANDLER
    ,
    CURSOR
    ,
    BEGIN...END
    ); AI agents often generate incorrect syntax — see Stored Procedures — MariaDB Docs
  • unix_socket
    认证
    ——无需密码即可认证OS用户;11.6+新增
    authentication_string
    支持以实现更细粒度的映射
  • ED25519插件——替代基于SHA1的插件的现代认证方式
  • PARSEC插件(11.6+,MDEV-32618)——使用椭圆曲线签名响应的密码认证;盐和每个安装的密钥分离使被盗哈希无法在其他地方使用
  • password_reuse_check
    插件
    (10.7+,MDEV-9245)——通过
    password_reuse_check_interval
    配置天数,防止密码重复使用
  • GRANT ... TO PUBLIC
    (10.11+,MDEV-5215)——一次语句向所有用户授予权限;搭配
    SHOW GRANTS FOR PUBLIC
    使用
  • SHOW CREATE ROUTINE
    权限
    (11.4+,MDEV-23149)——允许用户查看例程定义,无需授予
    mysql.proc
    SELECT
    权限
  • READ ONLY ADMIN
    成为独立权限
    (10.11+,MDEV-29596)——从
    SUPER
    中拆分出来,以便授予真正的只读副本角色;需要向
    read_only=1
    副本写入的现有账户需显式授予此权限
  • 基于角色的访问控制(10.0+)——MySQL添加此功能前MariaDB已支持角色
  • 默认SSL——自10.10起
    mariadb
    客户端默认启用SSL(MDEV-27105)。自11.4 LTS起服务器端默认要求SSL,自动生成自签名证书并自动进行客户端验证(
    tls_fp
    用于指纹固定)。
  • iv
    mode
    AES_ENCRYPT()
    /
    AES_DECRYPT()
    (11.4+,MDEV-30878)——
    AES_ENCRYPT(str, key, iv, mode)
    ;支持的模式包括CBC、OFB、CFB128、CTR(默认模式来自新的
    block_encryption_mode
    变量)。与MySQL的加密接口保持一致。
  • KDF()
    密钥派生函数
    (11.4+,MDEV-31474)——使用PBKDF2-HMAC或HKDF从密码短语派生加密密钥——
    AES_ENCRYPT(data, KDF('passw0rd', 'salt', 'info', 'hkdf'), iv)
    。请使用此函数而非直接将原始密码传入
    AES_ENCRYPT
  • RANDOM_BYTES(n)
    (10.10+,MDEV-25704)——从SSL库的RNG获取加密安全的随机字节(1–1024)
  • DES_ENCRYPT()
    /
    DES_DECRYPT()
    已弃用
    (10.10+,MDEV-27104)——旧DES密码;请使用
    AES_ENCRYPT
    /
    AES_DECRYPT
    搭配
    KDF()
    替代
  • 表级加密——加密单个表,而非整个数据目录
  • HashiCorp Vault集成——密钥管理插件

Storage Engines

复制与高可用

  • ColumnStore — columnar engine for analytical/data warehouse workloads
  • Aria — crash-safe MyISAM replacement, used internally for temp tables
  • MyRocks (10.2+) — RocksDB-based, optimized for write-heavy workloads with compression
  • CONNECT — query external data sources (CSV, JDBC, ODBC, MongoDB) as SQL tables
  • Spider — sharding across multiple MariaDB instances
  • Galera Cluster——内置同步多主集群
  • 多源复制——同时从多个主节点复制
  • 并行复制——更快的副本应用
  • 无延迟的
    ALTER TABLE
    复制
    ——架构变更不会停滞副本

Security & Auth

连接器

  • unix_socket
    authentication
    — authenticate OS users without passwords;
    authentication_string
    support added in 11.6+ for finer-grained mapping
  • ED25519 plugin — modern authentication alternative to SHA1-based plugins
  • PARSEC plugin (11.6+, MDEV-32618) — Password Authentication using Response Signed with Elliptic Curve; salt and per-installation key separation make stolen hashes unusable elsewhere
  • password_reuse_check
    plugin
    (10.7+, MDEV-9245) — prevent password reuse for a configurable number of days via
    password_reuse_check_interval
  • GRANT ... TO PUBLIC
    (10.11+, MDEV-5215) — grant privileges to all users in one statement; pair with
    SHOW GRANTS FOR PUBLIC
  • SHOW CREATE ROUTINE
    privilege
    (11.4+, MDEV-23149) — let users inspect a routine's definition without granting
    SELECT
    on
    mysql.proc
  • READ ONLY ADMIN
    is now a distinct privilege
    (10.11+, MDEV-29596) — split out of
    SUPER
    so a true read-only replica role can be granted; existing accounts that need to write to a
    read_only=1
    replica need this privilege granted explicitly
  • Role-based access control (10.0+) — roles available before MySQL added them
  • SSL by default — the
    mariadb
    client opts into SSL by default since 10.10 (MDEV-27105). The server side requires SSL by default since 11.4 LTS, with auto-generated self-signed certificates and automatic client-side verification (
    tls_fp
    for fingerprint-pinning).
  • AES_ENCRYPT()
    /
    AES_DECRYPT()
    with
    iv
    and
    mode
    (11.4+, MDEV-30878) —
    AES_ENCRYPT(str, key, iv, mode)
    ; supported modes include CBC, OFB, CFB128, CTR (default mode comes from the new
    block_encryption_mode
    variable). Brings parity with MySQL's encryption interface.
  • KDF()
    key-derivation function
    (11.4+, MDEV-31474) — derive an encryption key from a passphrase using PBKDF2-HMAC or HKDF —
    AES_ENCRYPT(data, KDF('passw0rd', 'salt', 'info', 'hkdf'), iv)
    . Use this rather than feeding a raw password into
    AES_ENCRYPT
    .
  • RANDOM_BYTES(n)
    (10.10+, MDEV-25704) — cryptographically secure random bytes (1–1024) from the SSL library's RNG
  • DES_ENCRYPT()
    /
    DES_DECRYPT()
    deprecated
    (10.10+, MDEV-27104) — old DES cipher; use
    AES_ENCRYPT
    /
    AES_DECRYPT
    with
    KDF()
    instead
  • Table-level encryption — encrypt individual tables, not just the whole datadir
  • HashiCorp Vault integration — key management plugin
  • LGPL许可的连接器——适用于C、C++、Java、Python、Node.js、ODBC、R2DBC——宽松许可适用于商业应用;MySQL连接器为GPL许可

Replication & HA

开发者工具

  • Galera Cluster — built-in synchronous multi-master clustering
  • Multi-source replication — replicate from multiple primaries simultaneously
  • Parallel replication — faster replica apply
  • Lag-free
    ALTER TABLE
    replication
    — schema changes don't stall replicas
  • 慢查询日志中的
    EXPLAIN
    ——自动记录慢查询的执行计划
  • ALTER TABLE
    CHECK TABLE
    的进度报告
  • mariadb-backup
    (10.1+)——带备份锁的热备份(无需
    FLUSH TABLES WITH READ LOCK
    )。备份需要两步——
    --prepare
    步骤在恢复前是必需的:
    bash
    mariadb-backup --backup --user=root --target-dir=/backup/full
    mariadb-backup --prepare --target-dir=/backup/full   # 应用重做日志——无此步骤则备份无法恢复
    对于Galera集群,添加
    --galera-info
    以捕获wsrep状态,以便集群干净重新加入。请勿使用
    innobackupex
    xtrabackup
    ——
    mariadb-backup
    是MariaDB的正确工具(10.1起包含,替代Percona依赖)。
  • 非阻塞客户端API——无需线程的异步查询

Connectors

新版本(12.x / 13.0)

  • LGPL-licensed connectors for C, C++, Java, Python, Node.js, ODBC, R2DBC — permissive licensing for commercial applications; MySQL connectors are GPL
这些功能需要MariaDB 12.0或更高版本(许多随12.3 LTS发布,目前为RC版本——请查看MariaDB版本了解正式发布状态)。当这些功能能解决用户问题或作为有意的升级路径时建议使用;请始终注明最低版本。

Developer Tools

SQL与架构

  • EXPLAIN
    in slow query log
    — automatic execution plan logging for slow queries
  • Progress reporting for
    ALTER TABLE
    and
    CHECK TABLE
  • mariadb-backup
    (10.1+) — hot backup with backup locks (no
    FLUSH TABLES WITH READ LOCK
    ). A backup requires two steps — the
    --prepare
    step is mandatory before restore:
    bash
    mariadb-backup --backup --user=root --target-dir=/backup/full
    mariadb-backup --prepare --target-dir=/backup/full   # apply redo logs — without this, the backup cannot be restored
    For Galera clusters, add
    --galera-info
    to capture the wsrep state for clean cluster rejoin. Do not use
    innobackupex
    or
    xtrabackup
    mariadb-backup
    is the correct tool for MariaDB (included since 10.1, replacing the Percona dependency).
  • Non-blocking client API — async queries without threads
  • 多事件触发的触发器(12.0+)——一个触发器体对应
    INSERT OR UPDATE OR DELETE
    ,而非三个单独的触发器
  • 每张表的外键名称(12.1+)——外键名称只需在每张表内唯一,无需在整个数据库内唯一(与MySQL兼容的行为)
  • JSON深度限制移除(12.2+)——JSON函数的32级嵌套限制已取消;深度嵌套的JSON现在无需重写即可工作
  • 从CTE读取的
    UPDATE
    /
    DELETE
    (12.3+)——
    WITH ... UPDATE/DELETE
    使用通用表表达式的值
  • IS JSON
    谓词
    (12.3+)——SQL标准测试,判断值是否为有效JSON:
    WHERE col IS JSON
  • 基础XML数据类型(12.3+)——用于存储和验证XML文档的一等
    XML
    类型
  • 原子
    CREATE OR REPLACE TABLE
    (13.0+)——语句完全原子:要么新表替换旧表,要么无任何变化,不会留下架构处于半替换状态的风险。MySQL无等效的原子保证。
  • UPDATE ... RETURNING
    (13.0+)——见RETURNING子句;11.8 LTS不可用

Newer releases (12.x / 13.0)

安全与认证

These require MariaDB 12.0 or newer (many ship with 12.3 LTS, currently RC — check MariaDB releases for GA status). Suggest them when they solve the user's problem or as a deliberate upgrade path; always name the minimum version.
  • SET SESSION AUTHORIZATION
    (12.0+)——在会话内以其他用户身份执行操作(适用于管理脚本和需要最小权限执行的应用中的模拟)
  • 带密码短语保护的TLS密钥(12.0+)——
    ssl_passphrase
    系统变量允许服务器加载加密的私钥

SQL & Schema

开发者工具

  • Triggers fired on multiple events (12.0+) — one trigger body for
    INSERT OR UPDATE OR DELETE
    , instead of three separate triggers
  • Foreign key names per table (12.1+) — FK names need to be unique only per table, not per database (MySQL-compatible behavior)
  • JSON depth limit removed (12.2+) — the 32-level nesting limit on JSON functions is gone; deeply nested JSON now works without rewrites
  • UPDATE
    /
    DELETE
    reading from a CTE
    (12.3+) —
    WITH ... UPDATE/DELETE
    using values from a common table expression
  • IS JSON
    predicate
    (12.3+) — SQL-standard test for whether a value is valid JSON:
    WHERE col IS JSON
  • Basic XML data type (12.3+) — first-class
    XML
    type for storing and validating XML documents
  • Atomic
    CREATE OR REPLACE TABLE
    (13.0+) — the statement is fully atomic: either the new table replaces the old one or nothing happens, with no risk of leaving the schema in a half-replaced state. MySQL has no equivalent atomic guarantee.
  • UPDATE ... RETURNING
    (13.0+) — see RETURNING Clause; not on 11.8 LTS
  • 弃用可见性(13.0+)——
    INFORMATION_SCHEMA.SYSTEM_VARIABLES
    包含deprecated标志,因此可在变量被移除前检测其使用情况,避免未来故障:
    sql
    SELECT variable_name, default_value FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE is_deprecated = 'YES';
  • INFORMATION_SCHEMA
    中可见的引擎特定创建选项
    (13.0+)——
    STATISTICS
    COLUMNS
    现在公开引擎特定选项,便于检查索引或列的配置方式

Security & Auth

来源

  • SET SESSION AUTHORIZATION
    (12.0+) — perform actions as another user within a session (useful for impersonation in administrative scripts and apps that need least-privilege execution)
  • Passphrase-protected TLS keys (12.0+) —
    ssl_passphrase
    system variable lets the server load encrypted private keys

Developer Tools

  • Deprecation visibility (13.0+) —
    INFORMATION_SCHEMA.SYSTEM_VARIABLES
    includes a deprecated flag, so you can detect uses of variables that will be removed in future versions before they break:
    sql
    SELECT variable_name, default_value FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE is_deprecated = 'YES';
  • Engine-specific create options visible in
    INFORMATION_SCHEMA
    (13.0+) —
    STATISTICS
    and
    COLUMNS
    now expose engine-specific options, useful when inspecting how indexes or columns were configured

Sources