MariaDB: The Community MySQL Fork

MariaDB: The Community MySQL Fork

MariaDB is the relational database most self-hosted applications will ask for, usually by asking for MySQL.

The fork

MariaDB was forked from MySQL in 2009 after Oracle’s acquisition, by MySQL’s original author. For basic use the two are interchangeable, and they have since diverged: different optimisers, different clustering, some different storage engines.

MariaDB is the default in most distribution repositories, which is why apt install mysql-server frequently installs MariaDB. Our MariaDB and MySQL guide covers the practical differences.

The three things to get right

Socket authentication. The root account authenticates through the unix socket plugin, trusting the operating system user. So sudo mariadb works with no password, which confuses people expecting a prompt. It is a good default: no credential to leak.

utf8mb4, not utf8. MySQL’s utf8 is a three-byte encoding that cannot store emoji or many CJK characters, and inserting one errors or truncates the row.

CREATE DATABASE myapp CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

This is the single most common data corruption problem in MySQL deployments, and current versions default correctly while upgraded-in-place databases keep whatever they were created with.

innodb_buffer_pool_size. How much data and index is cached in memory, and the one setting worth tuning. Around 70% of RAM on a dedicated server, considerably less when sharing with a web server, especially now that memory is expensive.

Backups that restore

mysqldump --single-transaction --routines --triggers myapp > myapp.sql

--single-transaction is not optional for InnoDB: without it the dump locks tables and your application stops. --routines and --triggers are not defaults, and a restore missing your stored procedures is discovered at the worst time.

For large databases, mariabackup copies data files and restores far faster than replaying a dump. Our automated backups guide covers scheduling and the point that an untested restore is a hypothesis.

Operational caution

Never expose port 3306 to the internet. Use a WireGuard tunnel or ssh tunnel if an application must reach it across an untrusted network.

Scope application accounts to one database. ALL PRIVILEGES ON *.* is how one compromised application becomes a compromised server.

License

MariaDB Server is released under the GNU General Public License v2.