Arch Linux installs MariaDB from the official repositories, but the database server will not start until you initialize /var/lib/mysql with mariadb-install-db. To install MariaDB on Arch Linux cleanly, choose the rolling mariadb package or the mariadb-lts branch, update the system with pacman, initialize the data directory, then start mariadb.service through systemd.
This workflow keeps the Arch package choices explicit, shows where MySQL-compatible names fit, and separates local socket access from network exposure so a development database does not accidentally become a remote service.
Install MariaDB on Arch Linux
Choose the MariaDB Package on Arch Linux
Arch provides two official MariaDB server branches. Install only one branch on a host because both packages provide MySQL-compatible service names and conflict with each other in pacman metadata.
| Package | Branch | Update Behavior | Best Fit |
|---|---|---|---|
mariadb | Current Arch MariaDB branch | Rolling package updates with new feature releases | General use, development systems, and servers that follow Arch’s normal rolling cadence |
mariadb-lts | MariaDB long-term support branch | Fewer branch changes, with maintenance updates inside the LTS series | Servers where application compatibility matters more than getting the newest MariaDB branch immediately |
Most Arch systems should use mariadb. Choose mariadb-lts when an application vendor documents a specific MariaDB LTS branch or when you want to reduce major-branch movement on a production host.
Update Arch Linux Before Installing MariaDB
Synchronize package databases and apply pending upgrades before installing the server. Arch does not support partial upgrades, so the package database and installed libraries should move together.
sudo pacman -Syu
These commands use
sudofor tasks that need root privileges. If your user is not in the sudoers file yet, run the commands as root or follow the guide on how to add and manage sudo users on Arch Linux.
Install the MariaDB Server Package
Install the standard MariaDB server package from Arch’s extra repository:
sudo pacman -S mariadb
Pacman installs the matching client package as a dependency. Verify the server and client package names after installation:
pacman -Qq mariadb mariadb-clients
mariadb mariadb-clients
For the LTS branch, install mariadb-lts instead. The LTS package pulls in mariadb-lts-clients, while user-facing commands such as mariadb, mariadb-dump, and mariadb-upgrade keep the same names.
sudo pacman -S mariadb-lts
Initialize the MariaDB Data Directory
Arch does not create the MariaDB system tables automatically. Initialize the data directory before starting the service:
sudo mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
The command creates the system database under /var/lib/mysql and creates local privileged accounts. The default root@localhost account has no database password, but it requires the system root identity, so use sudo mariadb for initial administration.
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
If the database directory resides on Btrfs, the Arch package includes a tmpfiles rule that disables Copy-on-Write for the MariaDB data directory. For ZFS-backed databases, review the Arch Wiki MariaDB page before production use because dataset record size and native AIO behavior can affect reliability.
Start and Verify MariaDB on Arch Linux
Start MariaDB now and enable it for future boots with the packaged systemd unit:
sudo systemctl enable mariadb --now
Verify the systemd state first. A healthy start should return active and enabled; if either command reports a different state, use the troubleshooting section before creating application databases.
systemctl is-active mariadb
systemctl is-enabled mariadb
Confirm the client package is callable. The exact MariaDB branch changes as Arch updates its repositories, so treat the version as current-state output rather than a fixed target.
mariadb --version
mariadb from 12.2.x-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1
Check the client and setup tool ownership when you need to prove the commands came from pacman packages:
command -v mariadb
pacman -Qo /usr/bin/mariadb /usr/bin/mariadb-install-db /usr/bin/mariadb-secure-installation
/usr/bin/mariadb /usr/bin/mariadb is owned by mariadb-clients 12.2.x-x /usr/bin/mariadb-install-db is owned by mariadb 12.2.x-x /usr/bin/mariadb-secure-installation is owned by mariadb 12.2.x-x
Secure MariaDB on Arch Linux
Run the bundled security helper after the service starts. It removes default test objects and lets you confirm how local root access should work.
sudo mariadb-secure-installation
Read each prompt instead of blindly answering the same value everywhere. A current Arch installation already creates a local root account that requires system root access, so the root-authentication prompt may differ from older examples.
- Root authentication: Keep socket-style local root access unless you intentionally need password-based root administration.
- Anonymous users: Remove anonymous accounts so unauthenticated local users cannot enter the server.
- Remote root login: Disallow remote root logins and create application-specific users instead.
- Test database: Remove the default test database and its broad privileges before using the host for real data.
- Privilege reload: Reload privilege tables when the helper asks so changes apply immediately.
Configure MariaDB Access on Arch Linux
MariaDB reads Arch server configuration from files under /etc/my.cnf.d/. Use /etc/my.cnf.d/server.cnf for normal server-level changes.
Check the Current TCP Listener
Before opening a firewall rule or changing a bind address, confirm whether MariaDB is listening on TCP port 3306:
sudo ss -ltnp 'sport = :3306'
If the database is only for local applications, keep the listener bound to localhost or disable TCP entirely. If another host must connect, bind to a specific private server address and protect the port with a firewall.
Keep MariaDB Local Only
Edit the server configuration file:
sudo nano /etc/my.cnf.d/server.cnf
Set an explicit IPv4 localhost bind address under the [mariadb] section when local TCP clients still need port 3306:
[mariadb]
bind-address = 127.0.0.1
For socket-only local access, disable networking instead:
[mariadb]
skip-networking
Restart MariaDB and recheck the service after any configuration change:
sudo systemctl restart mariadb
systemctl is-active mariadb
Allow Remote MariaDB Clients
Remote access needs three matching pieces: a bind address that accepts the connection, a database account with the correct host scope, and a firewall rule limited to trusted client addresses. The Arch Linux UFW guide and Arch Linux Firewalld guide cover the firewall layer.
Prefer a private interface address instead of binding to every network interface:
[mariadb]
bind-address = 192.0.2.10
Connect to MariaDB on Arch Linux
Use socket-authenticated local root access for initial administration:
sudo mariadb
If you intentionally configured password authentication for a database account, connect with the account name and password prompt instead:
mariadb -u root -p
A quick SQL version query confirms that the client can reach the server:
sudo mariadb -e "SELECT VERSION();"
+----------------+ | VERSION() | +----------------+ | 12.2.x-MariaDB | +----------------+
Create an Application Database and User
Create a dedicated database and user for each application instead of connecting applications as root. Start with a localhost-scoped account unless the application runs on another trusted host.
CREATE DATABASE app_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'replace_this_password';
GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
For a remote client, replace localhost with a narrow host value such as a single private IP address or a restricted subnet pattern. Do not use wildcard hosts for convenience on an internet-facing server.
Update and Upgrade MariaDB on Arch Linux
Normal MariaDB package updates arrive through pacman with the rest of the system:
sudo pacman -Syu
Before a major MariaDB branch change, take a logical backup. Use a restrictive file mode for the dump, and schedule downtime or use an application-specific backup plan when you rely on non-transactional tables.
umask 077
sudo mariadb-dump --all-databases --single-transaction --routines --events > mariadb-full-backup.sql
After a major branch update, run the upgrade helper from the matching client package:
sudo mariadb-upgrade
If you use password authentication instead of socket-authenticated root access, run the helper with a password prompt:
mariadb-upgrade -u root -p
Manage the MariaDB Service
Use systemctl for routine service control:
sudo systemctl stop mariadb
sudo systemctl start mariadb
sudo systemctl restart mariadb
systemctl status mariadb
sudo systemctl disable mariadb
sudo systemctl enable mariadb
Use restart after configuration edits, and use status or journalctl when troubleshooting a failed start.
Troubleshoot MariaDB on Arch Linux
MariaDB Fails Before Initialization
If the service fails immediately after installation, check the journal and confirm the system tables exist:
sudo journalctl -xeu mariadb
sudo ls /var/lib/mysql/mysql
If /var/lib/mysql/mysql is missing, stop the service and run the initialization command from the install section. Do not run mariadb-install-db over an existing data directory unless you are rebuilding disposable data and have already removed the old data intentionally.
Root Password Login Fails
A failed mariadb -u root -p login does not always mean root access is broken. On Arch, the initial root account is intended for system-root local access, so test with sudo mariadb first:
sudo mariadb
Use a separate administrative database user if you need password-based administration. Avoid emergency grant-table bypass reset flows unless you are following current upstream recovery documentation for the exact MariaDB branch and have console access to the host.
TCP Port 3306 Is Already in Use
If MariaDB reports a bind error, identify the process already listening on port 3306:
sudo ss -ltnp 'sport = :3306'
Stop the conflicting service, change MariaDB’s bind address or port, then restart MariaDB and recheck systemctl is-active mariadb.
Check and Repair Tables
After an unclean shutdown or storage issue, take a backup first, then run the table checker through local root socket access:
sudo mariadb-check --all-databases --auto-repair
InnoDB Errors on ZFS
ZFS-backed data directories can need extra tuning. If the journal shows InnoDB native AIO failures, disable native AIO in the MariaDB server configuration:
[mariadb]
innodb_use_native_aio = 0
Restart the service after saving the file, then review the journal again before returning the database to production use.
Remove MariaDB from Arch Linux
Stop and disable the service before removing packages:
sudo systemctl disable mariadb --now
Preview the package removal first so pacman shows which dependencies would also be removed:
sudo pacman -Rs mariadb --print
If the preview matches your intent, remove the standard branch with configuration backups and now-unneeded dependencies:
sudo pacman -Rns mariadb
Use mariadb-lts in those commands if you installed the LTS package instead.
Pacman package removal does not delete the database files in
/var/lib/mysql. Export or copy any databases you need before manually deleting that directory.
sudo rm -rf /var/lib/mysql
Verify that neither server branch remains installed:
pacman -Q mariadb || echo "mariadb is not installed"
pacman -Q mariadb-lts || echo "mariadb-lts is not installed"
Conclusion
MariaDB is ready for Arch workloads once pacman owns the server and client packages, /var/lib/mysql is initialized, and mariadb.service is managed through systemd. Keep application accounts scoped to one database, take backups before major branch upgrades, and expose TCP only when a firewall and host-specific grant require it. For web stacks, pair MariaDB with the Arch Linux PHP guide; for application designs that need a different SQL model, compare it with PostgreSQL on Arch Linux or SQLite on Arch Linux.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>