How to Install MariaDB on Any Linux Distribution — A Quick, Step-by-Step Guide
Ready to install MariaDB on Linux without the guesswork? This quick, step-by-step guide shows you how to add the official repo, install and secure the server, and tune settings so your database runs reliably on any distribution.
MariaDB is a popular open-source relational database that serves as a drop-in replacement for MySQL, favored for its performance, active community development, and feature set suitable for a wide range of applications from small websites to enterprise systems. This guide walks you through installing MariaDB on any Linux distribution, explains core concepts, recommended configuration for production, backup and replication options, and how to choose the right VPS offering to host your database. The instructions and explanations are written for system administrators, developers, and site owners who want practical, repeatable steps and deeper technical context.
Why MariaDB?
Before diving into installation details, it’s important to understand why you might choose MariaDB. MariaDB maintains compatibility with MySQL at the protocol and API level while adding performance optimizations, storage engine variety (Aria, ColumnStore, MyRocks in some builds), and features like dynamic columns, enhanced optimizer improvements, and improved replication including Galera-based clustering. For most web applications, MariaDB is a drop‑in replacement that can improve throughput and offer additional operational flexibility.
Common use cases
- Traditional LAMP/LEMP web stacks powering CMS (WordPress, Drupal) and frameworks.
- High-concurrency OLTP workloads where InnoDB tuning improves latency.
- Read-scale horizontal scaling with replication for reporting and analytics.
- High availability with Galera cluster for multi-master synchronous replication.
General installation strategy
Installation on Linux varies by distribution family. The most reliable approach is to use MariaDB’s official repositories because they provide more up-to-date packages than some distribution defaults. However, for quick setups, native distribution packages are acceptable. The high-level steps are:
- Add the MariaDB repository for your distribution (optional, but recommended).
- Install the server and client packages via the package manager.
- Start and enable the service (systemd or init script).
- Run the secure installation tasks and create necessary database users.
- Harden OS-level settings (firewall, SELinux/AppArmor, file permissions).
- Tune my.cnf for your workload and available RAM/CPU.
Distribution-specific steps
Debian / Ubuntu
Debian and Ubuntu ship MariaDB in their repositories, but the official MariaDB APT repo gives access to the latest stable series. To use MariaDB’s repo, create a repository file under /etc/apt/sources.list.d/ and add the appropriate line for your distribution and MariaDB version. Example steps (replace CODENAME and VERSION as appropriate):
1. Add the repository key and list entry for MariaDB. 2. sudo apt update. 3. sudo apt install mariadb-server mariadb-client.
After installation, enable and start the service: sudo systemctl enable –now mariadb. Run the built-in security script: sudo mysql_secure_installation to remove anonymous accounts, disable remote root login, and set a strong root password.
RHEL / CentOS / AlmaLinux / Rocky
For RHEL-based systems use YUM/DNF. Create a repo file under /etc/yum.repos.d/ for the desired MariaDB version. Then: sudo dnf install MariaDB-server MariaDB-client (or sudo yum install … on older releases). Start and enable: sudo systemctl enable –now mariadb. Remember to run mysql_secure_installation.
If SELinux is enforcing, ensure the process context and ports are correct. Typical actions:
- Allow network access on the MariaDB port: sudo semanage port -a -t mysqld_port_t -p tcp 3306 (if you change the port).
- Check file context for datadir if moved: sudo semanage fcontext -a -t mysqld_db_t “/path/to/datadir(/.*)?” && sudo restorecon -Rv /path/to/datadir
Fedora
Use DNF and the MariaDB Fedora repository if you want the latest MariaDB builds. Installation is similar to RHEL/CentOS.
Arch Linux
Arch provides MariaDB in the community repository. Use pacman -S mariadb. After installation, initialize the database directory if required (mysql_install_db or mariadb-install-db depending on package), and enable the service.
Generic tarball / Compiled from source
For special environments or custom builds, you can compile MariaDB from source or use binary tarballs. This path is more complex and requires building with the correct dependencies and running scripts to install systemd unit files, create users, and initialize the datadir. Only recommended for advanced users who need custom compile-time options.
Post-install configuration and hardening
After a successful install, there are several important steps to secure and optimize MariaDB:
1. Secure the installation
Run sudo mysql_secure_installation. It walks through setting a root password, removing anonymous users, disallowing remote root login, and removing test databases. For production, avoid simple passwords and consider integrating MariaDB with an identity provider (LDAP or PAM) where appropriate.
2. Network and firewall
By default, MariaDB listens on 0.0.0.0 if configured to do so. For most web applications on the same host, bind to the loopback (127.0.0.1) to reduce exposure. In /etc/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf set:
bind-address = 127.0.0.1
If you must allow remote access, open TCP port 3306 on your firewall (ufw, firewalld, iptables) and secure access with strong authentication and network-level restrictions (source IPs).
3. Basic performance tuning
Tuning should reflect available memory and workload type (OLTP vs OLAP). Key settings:
- innodb_buffer_pool_size: Set to 60–80% of system RAM on dedicated DB servers. This is the single most important parameter for InnoDB performance.
- innodb_log_file_size: Larger log files can improve write throughput and crash recovery characteristics; balance with recovery time.
- max_connections: Set to a reasonable value based on expected concurrency and application connection pooling.
- innodb_flush_method: O_DIRECT often avoids double-buffering when running on modern Linux filesystems.
- character-set-server = utf8mb4 and collation-server = utf8mb4_general_ci (or utf8mb4_unicode_ci) to support full Unicode, including emojis.
Always test changes on staging before applying to production; use SHOW ENGINE INNODB STATUS and performance_schema for diagnostics.
4. Backups and recovery
Choose a backup strategy that fits RTO/RPO goals:
- Logical backups: mysqldump is simple and portable. Example: mysqldump –single-transaction –routines –events –databases mydb > mydb.sql. Use –single-transaction for InnoDB to avoid long locks.
- Physical backups: mariabackup (MariaDB’s fork of XtraBackup) performs hot physical backups without downtime and is preferable for large datasets.
- Point-in-time recovery: enable binary logging (log_bin=ON) and regularly back up binlogs so you can replay transactions to a desired point.
5. Replication and high availability
MariaDB supports asynchronous replication (classic master-slave), semi-synchronous, GTID-based replication, and Galera multi-master clustering for synchronous replication. For read scaling, use asynchronous replication to feed read-only replicas. For multi-master HA, Galera is a strong option but requires planning for network topology, flow control tuning, and quorum considerations. When configuring replication:
- Ensure binary logging is enabled with a unique server-id for each instance.
- Use GTID (MariaDB GTID) for easier failover automation.
- Monitor replication lag using SHOW SLAVE STATUSG and tools like Monyog, Percona Monitoring, or Prometheus exporters.
Operational notes and monitoring
Monitoring and alerting are essential. Track metrics such as buffer pool usage, disk I/O, slow queries, connections, and replication lag. Use performance_schema and information_schema queries for diagnostics, and integrate with monitoring stacks: Prometheus + Grafana, Zabbix, or Datadog. Enable slow query logging for identifying problematic queries and optimize using EXPLAIN, indexing, and query rewriting.
Maintenance practices
- Rotate binary logs and purge old backups to avoid disk exhaustion.
- Perform regular OPTIMIZE TABLE or use online DDL tools for schema changes (ALTER TABLE … ALGORITHM=INPLACE where possible).
- Test backups regularly by performing restores to a staging host.
Which VPS should you pick for MariaDB?
Choosing the right hosting depends on dataset size, concurrency, and availability requirements. For low to medium workloads, a VPS with fast NVMe storage, at least 2 vCPUs, and 4–8 GB of RAM is a solid start. For larger production databases, prioritize RAM and disk IOPS over raw CPU. NVMe-backed SSDs with adequate IOPS reduce query latency, and dedicated CPU or CPU pinning can help predict performance under load.
If you’re exploring a reliable hosting option, consider providers that offer configurable VPS instances, DDoS protection, and multiple geographic locations. For example, VPS.DO offers a range of VPS plans in the USA that are suitable for hosting MariaDB instances; you can review options at https://vps.do/usa/. A managed or well-configured VPS makes it easier to scale and secure your database layer.
Summary
Installing MariaDB on any Linux distribution is straightforward if you follow distribution-specific package procedures or use MariaDB’s official repositories. After installation, prioritize security (mysql_secure_installation), configure networking and OS-level protections, and tune InnoDB settings based on RAM and workload. Implement a robust backup strategy using mysqldump for smaller datasets or mariabackup for large datasets, and plan replication or Galera clustering for scaling and high availability. Finally, choose a VPS that aligns with your performance and availability needs—look for fast storage and ample memory to get the most out of MariaDB.
For hosting choices tailored to database workloads, check out VPS.DO’s offerings. If you want a US-based VPS to run MariaDB with reliable NVMe storage and flexible resource allocation, see USA VPS at VPS.DO.