mariadb-features
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMariaDB 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 skill.
mariadb-vectorServer 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
大语言模型常忽略的点
| Situation | What to suggest instead |
|---|---|
Manual audit columns ( | |
| |
| |
IP addresses stored as | |
| Dropping or reordering columns with full table rebuild | |
| Oracle migration assumed to require full rewrite | |
| Asking what changed in a row over time | System-versioned tables with |
| Analytics queries on OLTP tables | ColumnStore engine — columnar storage for analytical workloads |
| Correlated subqueries for rankings, running totals, or per-group top-N | Window functions — |
| Deeply nested or repeated subqueries | Common Table Expressions — |
Assuming | In MariaDB |
Links or references to | The Knowledge Base no longer exists — all documentation is now at mariadb.com/docs |
| 场景 | 替代建议 |
|---|---|
手动审计列( | |
| |
使用 | |
IP地址存储为 | |
| 删除或重新排序列时需重建整张表 | |
| 假设从Oracle迁移需要完全重写 | |
| 查询某行随时间的变化 | 结合 |
| 在OLTP表上执行分析查询 | ColumnStore引擎 —— 面向分析型工作负载的列存储 |
| 使用关联子查询实现排名、累计求和或分组取Top-N | 窗口函数 —— |
| 深度嵌套或重复子查询 | 通用表表达式 —— |
假设 | MariaDB中的 |
链接或引用 | 知识库已不再存在——所有文档现在位于mariadb.com/docs |
Command-Line Tool Names (10.5+)
命令行工具名称(10.5+)
Since MariaDB 10.5, all command-line tools use prefixed names. Always generate the current names — the old names are retained as symlinks for compatibility but may be absent on minimal or container installs.
mariadb-mysql*| Deprecated name | Current name |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
自MariaDB 10.5起,所有命令行工具均使用前缀命名。请始终使用当前名称——旧的名称作为符号链接保留以兼容,但在最小化或容器安装中可能不存在。
mariadb-mysql*| 已弃用名称 | 当前名称 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
Provisioning and Initial Setup
配置与初始设置
AI agents default to MySQL 8 patterns for initial setup, which fail or mislead on MariaDB.
Database initialization — use (not , which is MySQL-specific):
mariadb-install-dbmysqld --initializebash
mariadb-install-dbRoot authentication — on a fresh install, uses authentication by default (no password). The correct first connection is:
rootunix_socketbash
sudo mariadbDo not generate for a fresh MariaDB install — there is no root password to enter.
mysql -u root -pSecure installation — use (not ).
mariadb-secure-installationmysql_secure_installationAI Agent默认采用MySQL 8的初始设置模式,这在MariaDB上会失败或产生误导。
数据库初始化——使用(而非MySQL专属的):
mariadb-install-dbmysqld --initializebash
mariadb-install-dbRoot认证——全新安装时,默认使用认证(无密码)。正确的首次连接方式为:
rootunix_socketbash
sudo mariadb请勿为全新MariaDB安装生成命令——此时没有root密码可输入。
mysql -u root -p安全安装——使用(而非)。
mariadb-secure-installationmysql_secure_installationUpgrade Operations
升级操作
Agents consistently omit the step after a binary upgrade, which can cause system table errors.
mariadb-upgradeStandard upgrade pattern:
bash
systemctl stop mariadbAgent始终会遗漏二进制升级后的步骤,这可能导致系统表错误。
mariadb-upgrade标准升级流程:
bash
systemctl stop mariadbReplace 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(11.6+, MDEV-19123) — new tables useutf8mb4unless overridden. Replication to MariaDB 10.6 or older replicas needs care (older replicas may not understand allutf8mb4collations).utf8mb4 - Default Unicode collation: (11.5+, MDEV-25829) — modern Unicode collation with proper SMP (supplementary multilingual plane) support including emoji. Replaces the older
uca1400_ai_cidefault.utf8mb4_general_ci - deprecated and ignored (11.5+, MDEV-33655) — specify
alter_algorithmon the statement itself instead.ALGORITHM=INSTANT|INPLACE|COPY - TIMESTAMP range extended (11.5+ 64-bit, MDEV-32188) — upper bound raised from to
2038-01-19 03:14:07 UTC. Storage format unchanged; old servers can still read values within the old range.2106-02-07 06:28:15 UTC - default ON — see next section.
innodb_snapshot_isolation
当前LTS版本(11.8)更改了多个长期存在的默认值。全新安装的行为与旧版本不同——迁移或比较行为时需注意:
- 默认字符集:→
latin1(11.6+,MDEV-19123)——新表默认使用utf8mb4,除非手动覆盖。向MariaDB 10.6或更早版本的副本复制时需谨慎(旧副本可能不支持所有utf8mb4排序规则)。utf8mb4 - 默认Unicode排序规则:(11.5+,MDEV-25829)——现代Unicode排序规则,支持完善的SMP(补充多语言平面),包括表情符号。替代了旧的
uca1400_ai_ci默认值。utf8mb4_general_ci - 已弃用并被忽略(11.5+,MDEV-33655)——请在语句本身指定
alter_algorithm。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, 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.
innodb_snapshot_isolationWhat 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 transactions are more likely to see write conflicts at commit time
REPEATABLE READ
If existing code depends on the older permissive behavior, opt back in explicitly:
sql
SET GLOBAL innodb_snapshot_isolation = OFF; -- restore pre-11.8 behaviorThe new default is the correct semantics — review code that relies on the looser behavior rather than disabling it long-term.
从MariaDB 11.8 LTS开始,默认设置为ON(此前为OFF,MDEV-35124)。这将REPEATABLE READ行为收紧为匹配真正的快照隔离——事务从开始时看到一致的快照,写入操作更严格地检测冲突。
innodb_snapshot_isolation现有代码可能发生的变化:
- 此前可静默运行的读取-修改-写入模式现在可能会触发冲突并报错——快速失败是预期行为
- 长时间运行的事务在提交时更可能遇到写入冲突
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 / columns or separate audit tables.
valid_fromvalid_toHistory grows without bound. Every UPDATE and DELETE appends a history row — MariaDB does not automatically expire history. Production deployments need eitherwith rotation (10.9+) or periodicPARTITION BY SYSTEM_TIMEto control disk growth. See theDELETE HISTORYskill for details.mariadb-system-versioned-tables
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_fromvalid_to历史记录会无限增长。 每次UPDATE和DELETE都会追加一条历史行——MariaDB不会自动过期历史记录。生产环境部署需要使用并设置轮转(10.9+),或定期执行PARTITION BY SYSTEM_TIME以控制磁盘占用。详情请查看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 or redesign:
SELECTsql
UPDATE orders SET qty = qty + 1 WHERE id = 42
RETURNING id, qty;11.8 LTS不可用——建议前确认服务器版本。旧版本中使用后续或重新设计:
SELECTsql
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_INCREMENTsql
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 valueSequences support gaps, multiple sequences per table, and descending sequences. Unlike , they are not tied to a specific column or table.
AUTO_INCREMENTMariaDB 10.3起可用。一等序列对象——比更灵活。
AUTO_INCREMENTsql
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_INCREMENTNon-Blocking ALTER TABLE (Instant + Online by Default)
非阻塞ALTER TABLE(默认Instant + Online)
MariaDB's works on a tiered model:
ALTER TABLE- (10.4+) — metadata-only changes (drop column, modify default, change column order, etc.) complete in microseconds without a table rebuild.
ALGORITHM=INSTANT - 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
ALGORITHM=COPY, LOCK=NONEis largely gone for routinept-online-schema-changes.ALTER - Optimistic two-phase replication of large (11.4+,
ALTER TABLE, off by default) — see thebinlog_alter_two_phase=1skill.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;
-- Non-instant change runs non-blocking by default on 11.2+:
ALTER TABLE large_table ADD INDEX (created_at);Use explicitly when you need to guarantee a metadata-only change; the operation will fail rather than silently fall back to a rebuild.
ALGORITHM=INSTANTMariaDB的采用分层模型:
ALTER TABLE- (10.4+)——仅元数据变更(删除列、修改默认值、调整列顺序等),微秒级完成,无需重建表。
ALGORITHM=INSTANT - 非Instant操作默认使用(11.2+,MDEV-16329)——即使需要重建表,MariaDB现在默认以非阻塞方式运行:复制过程中表上的并发DML可继续进行,仅在切换时短暂锁定。常规
ALGORITHM=COPY, LOCK=NONE操作基本不再需要ALTER等外部工具。pt-online-schema-change - 大型的乐观两阶段复制(11.4+,
ALTER TABLE,默认关闭)——详情请查看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=INSTANTINet4 and INet6 Data Types
INet4和INet6数据类型
INET6INET4VARCHARsql
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 (10.10+) when you know a column is IPv4-only and want the smaller storage; is the right default for mixed or IPv6-capable workloads.
INET4INET6INET6INET4VARCHARsql
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且需要更小存储空间时使用(10.10+);是混合或支持IPv6工作负载的合适默认选择。
INET4INET6Oracle Compatibility Mode
Oracle兼容模式
Available since MariaDB 10.3. enables PL/SQL syntax, Oracle-compatible NULL handling, packages, and Oracle-style functions — useful when migrating from Oracle or supporting Oracle-experienced developers.
sql_mode=ORACLEsql
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起可用。启用PL/SQL语法、Oracle兼容的NULL处理、包和Oracle风格函数——从Oracle迁移或支持有Oracle经验的开发者时非常有用。
sql_mode=ORACLEsql
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 utility, not a SQL statement:
mariadb-binlogbash
undefinedMariaDB 10.2起可用。使用二进制日志将表回滚到之前的状态——无需恢复完整备份。Flashback通过工具实现,而非SQL语句:
mariadb-binlogbash
-- 从二进制日志生成反向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 - (MINIMAL或NOBLOB模式省略反转所需的列值)
binlog_row_image = FULL
依赖FLASHBACK作为恢复路径前请验证:
sql
SHOW VARIABLES LIKE 'binlog_format'; -- 必须为ROW
SHOW VARIABLES LIKE 'binlog_row_image'; -- 必须为FULL需要启用二进制日志()。适用于恢复意外删除或错误迁移的数据。
log_binGenerate 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
/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 FULLRequires binary logging enabled (). Useful for recovering from accidental deletes or bad migrations.
log_bin- 不可见列(10.3+)——对隐藏,仍可写入;适用于架构演进而不破坏现有查询
SELECT * - BLOB/TEXT列支持表达式——MySQL不支持此功能
DEFAULT - 精度可达38位——MySQL最高为30位
DECIMAL - 和
INTERSECT(10.3+)——MySQL不支持的集合运算符EXCEPT - 子查询中支持——已支持;MySQL对此有限制
LIMIT - (10.6+,MDEV-23908)——SQL标准分页语法
SELECT ... OFFSET ... FETCH - 原子DDL(10.6+,MDEV-23842)——、
CREATE TABLE、ALTER TABLE、RENAME TABLE、DROP TABLE在支持的引擎(InnoDB、Aria、MyRocks)上是原子操作:DDL执行中途服务器崩溃,架构将保持语句执行前的状态,无需手动清理。多表DROP DATABASE对每个单独的删除是原子的,而非整个列表。DROP TABLE - (10.6+,MDEV-13115,仅InnoDB)——工作队列模式:工作线程获取下一个可用行并跳过其他事务正在处理的行,无锁等待
SELECT ... SKIP LOCKED - 忽略索引(10.6+,MDEV-7317)——保持索引更新但对优化器不可见。用于测试删除索引是否会影响性能,无需实际删除(重新启用即可零停机回滚)。
ALTER TABLE t ALTER INDEX idx IGNORED - 动态列(5.3+)——单列内的无架构键值存储
- (10.7+,MDEV-25015)——带位置占位符的字符串格式化函数
SFORMAT() - (10.7+,MDEV-4742)——生成“自然排序”的字符串排序键(例如
NATURAL_SORT_KEY()排在v9之前);适用于版本类或混合字母数字数据的v10ORDER BY - JSON增强——MariaDB在多个版本中逐步追平MySQL 8的JSON函数:
- /
JSON_EQUALS(a, b)(10.7+,MDEV-23143 / MDEV-16375)——语义相等性和规范化形式,用于哈希或唯一索引JSON_NORMALIZE(doc) - (10.9+,MDEV-27677)——检测两个文档之间共享的键/值或数组元素
JSON_OVERLAPS(a, b) - JSON路径语法支持负索引(、
$.A[-1])和范围($.A[last])(10.9+,MDEV-22224 / MDEV-27911)$.A[1 to 3] - (11.4+)——根据JSON Schema Draft 2020验证JSON,可用于
JSON_SCHEMA_VALID(schema, doc)约束CHECK - 、
JSON_KEY_VALUE、JSON_ARRAY_INTERSECT、JSON_OBJECT_TO_ARRAY(11.4+)——结构化操作原语,可与JSON_OBJECT_FILTER_KEYS良好组合JSON_TABLE - 和
UUID_v4()函数(11.7+)——生成版本4随机UUID或版本7时间有序UUID;v7形式可排序,非常适合作为主键UUID_v7() - (11.8+)——将字节数转换为人类可读字符串(例如
FORMAT_BYTES()→1234567)1.18 MiB - 扩展至62进制(11.4+,MDEV-30190)——
CONV()返回CONV(61,10,62);适用于短的不透明IDz - 函数及带可选初始值参数的
CRC32C()(10.8+,MDEV-27208)——Castagnoli多项式CRC,以及可链式校验的可种子化CRC32CRC32() - 单表支持表别名(11.6+)——
DELETE语法现在无需重写即可工作DELETE t FROM mytable t WHERE ... - (11.5+)——即使表看起来正常也强制修复
REPAIR TABLE ... FORCE - 存储过程参数默认值(11.8+,MDEV-10862)————调用时可传入更少参数
PROCEDURE p(a INT DEFAULT 0, b INT DEFAULT 0) - 存储函数/
IN/OUT参数限定符(10.8+,MDEV-10654)——使存储函数与存储过程参数模式保持一致INOUT - 存储函数返回数据类型(11.7+,MDEV-12252)——从存储函数返回结构化行
ROW - Oracle模式外支持/
CREATE PACKAGE(11.4+,MDEV-10075)——包例程在默认CREATE PACKAGE BODY下也可工作,不仅限于sql_modesql_mode=ORACLE - 更新触发器支持列列表(11.8+,MDEV-34551)————仅当这些列被更新时触发
CREATE TRIGGER ... BEFORE UPDATE OF col1, col2 ON t - 存储过程与函数——MariaDB使用SQL/PSM语法(、
DECLARE、HANDLER、CURSOR);AI Agent常生成错误语法——详见存储过程——MariaDB文档BEGIN...END
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 , still writable; useful for schema evolution without breaking existing queries
SELECT * - expressions on BLOB/TEXT — not supported in MySQL
DEFAULT - precision to 38 digits — MySQL stops at 30
DECIMAL - and
INTERSECT(10.3+) — set operators not available in MySQLEXCEPT - in subqueries — supported; MySQL restricts this
LIMIT - (10.6+, MDEV-23908) — SQL-standard pagination syntax
SELECT ... OFFSET ... FETCH - Atomic DDL (10.6+, MDEV-23842) — ,
CREATE TABLE,ALTER TABLE,RENAME TABLE,DROP TABLEare 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-tableDROP DATABASEis atomic per individual drop, not for the whole list.DROP TABLE - (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
SELECT ... SKIP LOCKED - Ignored Indexes (10.6+, MDEV-7317) — 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).
ALTER TABLE t ALTER INDEX idx IGNORED - Dynamic columns (5.3+) — schema-less key/value storage inside a single column
- (10.7+, MDEV-25015) — string formatting function with positional placeholders
SFORMAT() - (10.7+, MDEV-4742) — produces a sort key that orders strings "naturally" (so
NATURAL_SORT_KEY()sorts beforev9); useful inv10for version-like or mixed-alphanumeric dataORDER BY - JSON enhancements — MariaDB has been catching up to MySQL 8 JSON functions over several releases:
- /
JSON_EQUALS(a, b)(10.7+, MDEV-23143 / MDEV-16375) — semantic equality and canonical form for hashing or unique indexingJSON_NORMALIZE(doc) - (10.9+, MDEV-27677) — detect shared key/value or array elements between two documents
JSON_OVERLAPS(a, b) - JSON path syntax supports negative indices (,
$.A[-1]) and ranges ($.A[last]) (10.9+, MDEV-22224 / MDEV-27911)$.A[1 to 3] - (11.4+) — validate JSON against a JSON Schema Draft 2020 schema, usable inside
JSON_SCHEMA_VALID(schema, doc)constraintsCHECK - ,
JSON_KEY_VALUE,JSON_ARRAY_INTERSECT,JSON_OBJECT_TO_ARRAY(11.4+) — structural manipulation primitives that compose well withJSON_OBJECT_FILTER_KEYSJSON_TABLE
- and
UUID_v4()functions (11.7+) — generate version-4 random or version-7 time-ordered UUIDs; the v7 form is sortable and ideal for primary keysUUID_v7() - (11.8+) — convert a byte count to a human-readable string (e.g.
FORMAT_BYTES()→1234567)1.18 MiB - extended to base 62 (11.4+, MDEV-30190) —
CONV()returnsCONV(61,10,62); useful for short opaque IDsz - function and
CRC32C()with optional initial-value argument (10.8+, MDEV-27208) — Castagnoli polynomial CRC, and seedable CRC32 for chained checksumsCRC32() - Single-table with table aliases (11.6+) —
DELETEsyntax now works without rewritingDELETE t FROM mytable t WHERE ... - (11.5+) — force-repair even when the table appears clean
REPAIR TABLE ... FORCE - Stored routine parameter default values (11.8+, MDEV-10862) — — call with fewer arguments
PROCEDURE p(a INT DEFAULT 0, b INT DEFAULT 0) - Stored function /
IN/OUTparameter qualifiers (10.8+, MDEV-10654) — bring stored functions in line with stored procedure parameter modesINOUT - data type as stored function return value (11.7+, MDEV-12252) — return structured rows from stored functions
ROW - /
CREATE PACKAGEoutside Oracle mode (11.4+, MDEV-10075) — package routines work under the defaultCREATE PACKAGE BODYtoo, not only withsql_modesql_mode=ORACLE - Update triggers with column list (11.8+, MDEV-34551) — — fire only when those columns are updated
CREATE TRIGGER ... BEFORE UPDATE OF col1, col2 ON t - Stored procedures and functions — MariaDB uses SQL/PSM syntax (,
DECLARE,HANDLER,CURSOR); AI agents often generate incorrect syntax — see Stored Procedures — MariaDB DocsBEGIN...END
- 认证——无需密码即可认证OS用户;11.6+新增
unix_socket支持以实现更细粒度的映射authentication_string - ED25519插件——替代基于SHA1的插件的现代认证方式
- PARSEC插件(11.6+,MDEV-32618)——使用椭圆曲线签名响应的密码认证;盐和每个安装的密钥分离使被盗哈希无法在其他地方使用
- 插件(10.7+,MDEV-9245)——通过
password_reuse_check配置天数,防止密码重复使用password_reuse_check_interval - (10.11+,MDEV-5215)——一次语句向所有用户授予权限;搭配
GRANT ... TO PUBLIC使用SHOW GRANTS FOR PUBLIC - 权限(11.4+,MDEV-23149)——允许用户查看例程定义,无需授予
SHOW CREATE ROUTINE的mysql.proc权限SELECT - 成为独立权限(10.11+,MDEV-29596)——从
READ ONLY ADMIN中拆分出来,以便授予真正的只读副本角色;需要向SUPER副本写入的现有账户需显式授予此权限read_only=1 - 基于角色的访问控制(10.0+)——MySQL添加此功能前MariaDB已支持角色
- 默认SSL——自10.10起客户端默认启用SSL(MDEV-27105)。自11.4 LTS起服务器端默认要求SSL,自动生成自签名证书并自动进行客户端验证(
mariadb用于指纹固定)。tls_fp - 带和
iv的mode/AES_ENCRYPT()(11.4+,MDEV-30878)——AES_DECRYPT();支持的模式包括CBC、OFB、CFB128、CTR(默认模式来自新的AES_ENCRYPT(str, key, iv, mode)变量)。与MySQL的加密接口保持一致。block_encryption_mode - 密钥派生函数(11.4+,MDEV-31474)——使用PBKDF2-HMAC或HKDF从密码短语派生加密密钥——
KDF()。请使用此函数而非直接将原始密码传入AES_ENCRYPT(data, KDF('passw0rd', 'salt', 'info', 'hkdf'), iv)。AES_ENCRYPT - (10.10+,MDEV-25704)——从SSL库的RNG获取加密安全的随机字节(1–1024)
RANDOM_BYTES(n) - /
DES_ENCRYPT()已弃用(10.10+,MDEV-27104)——旧DES密码;请使用DES_DECRYPT()/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
连接器
- authentication — authenticate OS users without passwords;
unix_socketsupport added in 11.6+ for finer-grained mappingauthentication_string - 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
- plugin (10.7+, MDEV-9245) — prevent password reuse for a configurable number of days via
password_reuse_checkpassword_reuse_check_interval - (10.11+, MDEV-5215) — grant privileges to all users in one statement; pair with
GRANT ... TO PUBLICSHOW GRANTS FOR PUBLIC - privilege (11.4+, MDEV-23149) — let users inspect a routine's definition without granting
SHOW CREATE ROUTINEonSELECTmysql.proc - is now a distinct privilege (10.11+, MDEV-29596) — split out of
READ ONLY ADMINso a true read-only replica role can be granted; existing accounts that need to write to aSUPERreplica need this privilege granted explicitlyread_only=1 - Role-based access control (10.0+) — roles available before MySQL added them
- SSL by default — the 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 (
mariadbfor fingerprint-pinning).tls_fp - /
AES_ENCRYPT()withAES_DECRYPT()andiv(11.4+, MDEV-30878) —mode; supported modes include CBC, OFB, CFB128, CTR (default mode comes from the newAES_ENCRYPT(str, key, iv, mode)variable). Brings parity with MySQL's encryption interface.block_encryption_mode - key-derivation function (11.4+, MDEV-31474) — derive an encryption key from a passphrase using PBKDF2-HMAC or HKDF —
KDF(). Use this rather than feeding a raw password intoAES_ENCRYPT(data, KDF('passw0rd', 'salt', 'info', 'hkdf'), iv).AES_ENCRYPT - (10.10+, MDEV-25704) — cryptographically secure random bytes (1–1024) from the SSL library's RNG
RANDOM_BYTES(n) - /
DES_ENCRYPT()deprecated (10.10+, MDEV-27104) — old DES cipher; useDES_DECRYPT()/AES_ENCRYPTwithAES_DECRYPTinsteadKDF() - 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 replication — schema changes don't stall replicas
ALTER TABLE
- 慢查询日志中的——自动记录慢查询的执行计划
EXPLAIN - 和
ALTER TABLE的进度报告CHECK TABLE - (10.1+)——带备份锁的热备份(无需
mariadb-backup)。备份需要两步——FLUSH TABLES WITH READ LOCK步骤在恢复前是必需的:--prepare对于Galera集群,添加bashmariadb-backup --backup --user=root --target-dir=/backup/full mariadb-backup --prepare --target-dir=/backup/full # 应用重做日志——无此步骤则备份无法恢复以捕获wsrep状态,以便集群干净重新加入。请勿使用--galera-info或innobackupex——xtrabackup是MariaDB的正确工具(10.1起包含,替代Percona依赖)。mariadb-backup - 非阻塞客户端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与架构
- in slow query log — automatic execution plan logging for slow queries
EXPLAIN - Progress reporting for and
ALTER TABLECHECK TABLE - (10.1+) — hot backup with backup locks (no
mariadb-backup). A backup requires two steps — theFLUSH TABLES WITH READ LOCKstep is mandatory before restore:--prepareFor Galera clusters, addbashmariadb-backup --backup --user=root --target-dir=/backup/full mariadb-backup --prepare --target-dir=/backup/full # apply redo logs — without this, the backup cannot be restoredto capture the wsrep state for clean cluster rejoin. Do not use--galera-infoorinnobackupex—xtrabackupis the correct tool for MariaDB (included since 10.1, replacing the Percona dependency).mariadb-backup - 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(12.3+)——DELETE使用通用表表达式的值WITH ... UPDATE/DELETE - 谓词(12.3+)——SQL标准测试,判断值是否为有效JSON:
IS JSONWHERE col IS JSON - 基础XML数据类型(12.3+)——用于存储和验证XML文档的一等类型
XML - 原子(13.0+)——语句完全原子:要么新表替换旧表,要么无任何变化,不会留下架构处于半替换状态的风险。MySQL无等效的原子保证。
CREATE OR REPLACE TABLE - (13.0+)——见RETURNING子句;11.8 LTS不可用
UPDATE ... RETURNING
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.
- (12.0+)——在会话内以其他用户身份执行操作(适用于管理脚本和需要最小权限执行的应用中的模拟)
SET SESSION AUTHORIZATION - 带密码短语保护的TLS密钥(12.0+)——系统变量允许服务器加载加密的私钥
ssl_passphrase
SQL & Schema
开发者工具
- Triggers fired on multiple events (12.0+) — one trigger body for , instead of three separate triggers
INSERT OR UPDATE OR DELETE - 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
- /
UPDATEreading from a CTE (12.3+) —DELETEusing values from a common table expressionWITH ... UPDATE/DELETE - predicate (12.3+) — SQL-standard test for whether a value is valid JSON:
IS JSONWHERE col IS JSON - Basic XML data type (12.3+) — first-class type for storing and validating XML documents
XML - Atomic (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.
CREATE OR REPLACE TABLE - (13.0+) — see RETURNING Clause; not on 11.8 LTS
UPDATE ... RETURNING
- 弃用可见性(13.0+)——包含deprecated标志,因此可在变量被移除前检测其使用情况,避免未来故障:
INFORMATION_SCHEMA.SYSTEM_VARIABLESsqlSELECT variable_name, default_value FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE is_deprecated = 'YES'; - 中可见的引擎特定创建选项(13.0+)——
INFORMATION_SCHEMA和STATISTICS现在公开引擎特定选项,便于检查索引或列的配置方式COLUMNS
Security & Auth
来源
- (12.0+) — perform actions as another user within a session (useful for impersonation in administrative scripts and apps that need least-privilege execution)
SET SESSION AUTHORIZATION - Passphrase-protected TLS keys (12.0+) — system variable lets the server load encrypted private keys
ssl_passphrase
- Monty Widenius: Celebrating 15 years of MariaDB
- MariaDB vs MySQL Features — MariaDB Docs
- System-Versioned Tables — MariaDB Docs
- RETURNING — MariaDB Docs
- CREATE SEQUENCE — MariaDB Docs
- Instant ALTER TABLE — MariaDB Docs
- INet6 Data Type — MariaDB Docs
- Oracle Compatibility — MariaDB Docs
- FLASHBACK — MariaDB Docs
未涵盖的主题,请查看官方MariaDB文档mariadb.com/docs。
Developer Tools
—
- Deprecation visibility (13.0+) — includes a deprecated flag, so you can detect uses of variables that will be removed in future versions before they break:
INFORMATION_SCHEMA.SYSTEM_VARIABLESsqlSELECT variable_name, default_value FROM INFORMATION_SCHEMA.SYSTEM_VARIABLES WHERE is_deprecated = 'YES'; - Engine-specific create options visible in (13.0+) —
INFORMATION_SCHEMAandSTATISTICSnow expose engine-specific options, useful when inspecting how indexes or columns were configuredCOLUMNS
—
Sources
—
- Monty Widenius: Celebrating 15 years of MariaDB
- MariaDB vs MySQL Features — MariaDB Docs
- System-Versioned Tables — MariaDB Docs
- RETURNING — MariaDB Docs
- CREATE SEQUENCE — MariaDB Docs
- Instant ALTER TABLE — MariaDB Docs
- INet6 Data Type — MariaDB Docs
- Oracle Compatibility — MariaDB Docs
- FLASHBACK — MariaDB Docs
For topics not covered here, see the official MariaDB documentation at mariadb.com/docs.
—