MariaDB is a community-developed fork of MySQL that has been Arch Linux’s default MySQL implementation since 2013. It provides full MySQL compatibility with additional storage engines and performance improvements, making it suitable for web applications, development environments, and production servers.
Choose Your MariaDB Package
Arch Linux provides two MariaDB packages in the official repositories, each targeting different use cases:
| Package | Version | Updates | Best For |
|---|---|---|---|
| mariadb | Latest stable (12.x) | Rolling updates with new features | Development and users wanting latest features |
| mariadb-lts | LTS release (11.x) | Security fixes, extended support cycle | Production servers prioritizing stability |
For most users, the standard mariadb package is recommended because Arch Linux is a rolling-release distribution where frequent updates are expected. The LTS package suits production environments where you prefer fewer feature changes between updates.
Update Arch Linux
Before installing new packages, synchronize the package database and upgrade all installed packages to ensure compatibility:
sudo pacman -Syu
On a rolling-release distribution, keeping packages synchronized prevents dependency conflicts during installation.
Install MariaDB
Install the MariaDB server package from the official Arch Linux repositories:
sudo pacman -S mariadb
For the LTS version, replace
mariadbwithmariadb-ltsin the command above. The LTS package providesmariadb-lts-clientsinstead ofmariadb-clients, but all command names remain identical.
Initialize the Database
MariaDB requires an initialized data directory before the service can start. Run the database initialization script to create the system tables:
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
This creates the MySQL system databases in /var/lib/mysql/ and sets up two privileged accounts: root@localhost (accessible via sudo) and mysql@localhost (accessible as the mysql system user). Neither account has a password initially.
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ... OK Two all-privilege accounts were created. One is root@localhost, it has no password, but you need to be system 'root' user to connect. Use, for example, sudo mariadb The second is mysql@localhost, it has no password either, but you need to be the system 'mysql' user to connect.
If your database directory resides on a Btrfs filesystem, the MariaDB package automatically disables Copy-on-Write via a systemd-tmpfiles configuration. ZFS users should set
recordsize=16Kon the dataset and consider disablingaio_writesin the MariaDB configuration if you encounter OS error 22. See the Arch Wiki MariaDB page for filesystem-specific guidance.
Start and Enable the MariaDB Service
Start the MariaDB service and configure it to launch automatically at boot:
sudo systemctl enable mariadb --now
The --now flag combines the enable and start operations into a single command. Verify that the service is running:
systemctl status mariadb
● mariadb.service - MariaDB 12.1.2 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
Active: active (running) since Fri 2026-01-17 11:15:32 UTC; 5s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 1234 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 8 (limit: 4915)
Memory: 78.5M
CPU: 312ms
CGroup: /system.slice/mariadb.service
└─1234 /usr/bin/mariadbd
Confirm the installation by checking the MariaDB version:
mariadb --version
mariadb from 12.1.2-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
Secure the MariaDB Installation
Fresh MariaDB installations include default settings that should be hardened before production use. The security script walks through recommended changes interactively:
sudo mariadb-secure-installation
The script prompts for several security decisions:
- Switch to unix_socket authentication: Recommended. This ties database root access to system root access, eliminating the need for a separate database password while preventing network-based password attacks.
- Change the root password: Set a strong password if you choose password authentication instead of unix_socket.
- Remove anonymous users: Recommended. Anonymous accounts allow anyone to connect without credentials.
- Disallow root login remotely: Recommended. Root should only connect from localhost; create separate accounts for remote access.
- Remove test database: Recommended. The test database is accessible to anonymous users and serves no production purpose.
- Reload privilege tables: Apply changes immediately.
Answer Y to each prompt to apply the recommended security settings:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
... Success!
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Configure MariaDB
MariaDB configuration files on Arch Linux are located in /etc/my.cnf.d/. The main server configuration file is /etc/my.cnf.d/server.cnf.
Restrict Network Access
By default, MariaDB listens on all network interfaces (0.0.0.0). For local-only database access, restrict binding to localhost by editing the server configuration:
sudo nano /etc/my.cnf.d/server.cnf
Add the following under the [mariadb] section:
[mariadb]
bind-address = localhost
This binds to both 127.0.0.1 (IPv4) and ::1 (IPv6). For environments where MariaDB should only be accessible via Unix sockets (not TCP at all), use:
[mariadb]
skip-networking
Restart the service to apply configuration changes:
sudo systemctl restart mariadb
Character Encoding
The Arch Linux MariaDB package defaults to utf8mb4 with utf8mb4_unicode_ci collation, which supports the full Unicode character set including emoji. No configuration is required for standard use. To verify or customize these settings, check /etc/my.cnf.d/server.cnf:
[mariadb]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Connect to MariaDB
With unix_socket authentication enabled, connect to MariaDB as the database root user by running mariadb with sudo:
sudo mariadb
If you configured password authentication instead, use:
mariadb -u root -p
The MariaDB prompt confirms a successful connection:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 12.1.2-MariaDB Arch Linux Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
Create a Database and User
Create a new database and a dedicated user with permissions for that database. This is the recommended approach rather than using the root account for applications:
CREATE DATABASE myapp_db;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Replace myapp_db, myapp_user, and secure_password with your actual values. The FLUSH PRIVILEGES command reloads the grant tables to apply the changes immediately.
Upgrade Database Tables After Major Updates
When upgrading between major MariaDB versions through pacman (for example, 11.x to 12.x), run the upgrade tool to update system tables:
sudo mariadb-upgrade
If you use password authentication instead of unix_socket, run:
mariadb-upgrade -u root -p
This checks and repairs system tables, converting them to the new format if necessary. Skip this step on fresh installations as the tables are already current.
Phase 1/8: Checking and upgrading mysql database Processing databases mysql mysql.column_stats OK mysql.columns_priv OK mysql.db OK ... Phase 8/8: Running 'FLUSH PRIVILEGES' OK
Manage the MariaDB Service
Use systemctl to control the MariaDB service:
# Stop the service
sudo systemctl stop mariadb
# Start the service
sudo systemctl start mariadb
# Restart the service (apply configuration changes)
sudo systemctl restart mariadb
# Check service status
systemctl status mariadb
# Disable automatic startup at boot
sudo systemctl disable mariadb
# Re-enable automatic startup
sudo systemctl enable mariadb
Troubleshoot Common Issues
Service Fails to Start
If MariaDB fails to start, check the journal for error messages:
journalctl -xeu mariadb
Common causes include missing data directory initialization or permission issues on /var/lib/mysql/. Ensure the mysql user owns the data directory:
sudo chown -R mysql:mysql /var/lib/mysql
Reset the Root Password
If you lose the root password, reset it by starting MariaDB without grant table checks:
sudo systemctl stop mariadb
sudo mariadbd-safe --skip-grant-tables --skip-networking &
Connect without a password and reset:
mariadb -u root
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
EXIT;
Stop the standalone process and restart the service normally:
sudo kill $(cat /var/lib/mysql/*.pid)
sudo systemctl start mariadb
Check and Repair Tables
If you experience database corruption or errors after an unexpected shutdown, check and repair tables:
sudo mariadb-check --all-databases --auto-repair -u root -p
InnoDB Errors on ZFS
ZFS users may encounter InnoDB: Operating system error number 22. Disable native AIO in the MariaDB configuration:
[mariadb]
innodb_use_native_aio = 0
Restart MariaDB after saving the configuration.
Remove MariaDB
To completely remove MariaDB from your system, first stop and disable the service:
sudo systemctl stop mariadb
sudo systemctl disable mariadb
Remove the package along with its dependencies and configuration files:
sudo pacman -Rns mariadb
The -Rns flags remove the package (-R), its orphaned dependencies (-s), and backup configuration files (-n).
The database files in
/var/lib/mysql/are not removed by pacman to prevent accidental data loss. If you want to completely remove all databases, export any data you need to keep first, then manually delete the data directory.
To remove the database directory after backing up important data:
sudo rm -rf /var/lib/mysql
Verify removal by checking the package status:
pacman -Qi mariadb
error: package 'mariadb' was not found
Conclusion
You now have a secured MariaDB installation on Arch Linux with the database initialized, security settings applied, and an understanding of service management and troubleshooting. For web applications like WordPress or frameworks requiring MySQL-compatible databases, create dedicated database users with limited privileges rather than using root. The Arch Wiki MariaDB page and MariaDB Knowledge Base provide additional configuration options for replication, backup strategies, and performance tuning.