How to Install MariaDB on Linux: A Step‑by‑Step Guide for Ubuntu, CentOS & Fedora
Ready to power your web apps with a fast, drop‑in MySQL replacement? This step‑by‑step guide shows how to install MariaDB on Linux (Ubuntu, CentOS and Fedora) and walks you through setup, performance tips and security best practices so you can deploy with confidence.
Introduction
MariaDB is a widely adopted open-source relational database that is fully compatible with MySQL while offering performance enhancements, additional storage engines and active community-driven development. For webmasters, developers and enterprise users deploying applications on virtual private servers, knowing how to install and configure MariaDB on major Linux distributions is essential. This guide provides a detailed, practical walkthrough for Ubuntu, CentOS and Fedora, along with architecture considerations, common use cases, performance and security tips, and deployment recommendations.
Why choose MariaDB: principle and advantages
Architectural compatibility and active development — MariaDB maintains compatibility with MySQL client protocols and SQL dialects while evolving faster with new features (e.g., Aria, ColumnStore, MyRocks). This makes it a low-friction replacement for existing MySQL deployments.
Multiple storage engines — Beyond InnoDB, MariaDB ships with storage engines optimized for different workloads: Aria for crash-safe temporary tables, XtraDB forks, ColumnStore for analytics, and MyRocks for write-heavy scenarios.
Enterprise features — Built-in Galera cluster support for synchronous multi-master replication, dynamic columns, improved optimizer traces, and pluggable authentication allow MariaDB to serve from small web apps to multi-node enterprise databases.
Common application scenarios
- Single-node LAMP/LEMP stacks for CMSs (WordPress, Drupal, Joomla)
- High-availability (HA) web services using Galera clusters across VPS nodes
- Data warehousing and analytics with ColumnStore or optimized read replicas
- Write-intensive workloads leveraging MyRocks or tuned InnoDB configurations
Preparations before installation
Before installing, ensure your server meets basic prerequisites: a supported Linux distribution release, sufficient RAM (4+ GB recommended for production database servers), and proper time synchronization (systemd-timesyncd or chrony). If running on cloud or VPS, provisioned I/O characteristics matter: choose SSD-backed instances for database workloads. Also ensure your package manager metadata is up-to-date.
Install on Ubuntu (LTS)
1) Add MariaDB repository (recommended for latest stable)
On Ubuntu, it is common to use the MariaDB APT repository to get newer versions than the distro provides. Create a repository file or use the MariaDB repository configuration tool. For example, to add MariaDB 10.6 for Ubuntu 22.04:
apt update && apt install -y software-properties-common dirmngr
curl -LsS https://downloads.mariadb.org/mariadb_repo_setup | sudo bash -s — –mariadb-server-version=10.6
2) Install packages
Then install the server and client packages:
sudo apt update && sudo apt install -y mariadb-server mariadb-client
3) Initialize and start service
Systemd manages the MariaDB service. Start and enable it:
sudo systemctl enable –now mariadb
Verify status with: sudo systemctl status mariadb
4) Secure initial installation
Run the built-in script to set root password, remove test DBs and anonymous users:
sudo mysql_secure_installation
Follow prompts to enforce strong authentication and remove insecure defaults.
Install on CentOS / RHEL
1) Add the MariaDB YUM repository
Create a repo file under /etc/yum.repos.d/ pointing to the MariaDB yum repo. Example for MariaDB 10.6:
sudo tee /etc/yum.repos.d/MariaDB.repo <<‘EOF’n[mariadb]nname = MariaDBnbaseurl = http://yum.mariadb.org/10.6/centos8-amd64ngpgkey=https://rpm.mariadb.org/RPM-GPG-KEY-MariaDBngpgcheck=1nEOF
2) Install with DNF/YUM
On CentOS 8 / RHEL 8 or newer:
sudo dnf install -y MariaDB-server MariaDB-client
3) Start and enable
sudo systemctl enable –now mariadb
Check: sudo systemctl status mariadb
4) SELinux & Firewall
If SELinux is enforcing, apply correct file contexts for custom data directories and allow network binding:
sudo semanage port -a -t mysqld_port_t -p tcp 3306
Open firewall port if remote connections are needed:
sudo firewall-cmd –permanent –add-service=mysql && sudo firewall-cmd –reload
Install on Fedora
Fedora usually includes recent MariaDB packages. Use DNF to install:
sudo dnf install -y mariadb-server mariadb
Then start and enable:
sudo systemctl enable –now mariadb
The same post-install security steps apply (mysql_secure_installation). For the latest releases, use the MariaDB repos if you require a specific version.
Essential configurations and tuning
1) Data directory and file permissions
The default data directory is /var/lib/mysql. For performance or storage separation, move it to a dedicated volume with proper ownership (mysql:mysql) and SELinux context if applicable. Example:
sudo systemctl stop mariadb; sudo rsync -av /var/lib/mysql /mnt/dbdata; sudo mv /var/lib/mysql /var/lib/mysql.bak; sudo ln -s /mnt/dbdata/mysql /var/lib/mysql; sudo systemctl start mariadb
2) my.cnf tuning
Tune InnoDB settings in /etc/mysql/my.cnf or /etc/my.cnf. Key parameters:
- innodb_buffer_pool_size — set to 60–80% of available RAM for dedicated DB servers
- innodb_log_file_size — larger sizes (512M–1G) reduce checkpoint frequency for write-heavy workloads
- innodb_flush_method = O_DIRECT — avoids double buffering on Linux
- max_connections — set according to expected concurrency and available resources
3) Performance schema and monitoring
Enable performance_schema for advanced diagnostics and use tools like mariadb-monitoring scripts, Percona Toolkit, or Prometheus exporters for long-term observability.
Security best practices
- Use strong authentication: remove root network access, use unix_socket plugin for local root access, and create least-privilege users for applications.
- Enable TLS/SSL: generate server certificates and configure ssl_cert, ssl_key and require SSL for remote user accounts if transporting sensitive data.
- Regular updates: track MariaDB security advisories and apply patches promptly. Use the MariaDB repository for timely updates.
- Backups: use logical backups (mysqldump) for small databases and physical backups (mariabackup / xtrabackup) for large datasets with point-in-time recovery.
- Audit and logs: enable general/slow query logs and consider the audit plugin for compliance requirements.
Replication and high-availability options
MariaDB supports multiple replication topologies:
- Asynchronous master-slave replication for read scaling and simple failover
- Multi-source replication to consolidate multiple masters’ data
- Synchronous replication via Galera for multi-master HA clusters (MariaDB Galera Cluster)
Basic asynchronous replication setup includes enabling binary logging (log_bin), unique server_id values, creating a replication user with REPLICATION SLAVE privilege, and applying the snapshot on the replica with CHANGE MASTER TO commands. For HA, Galera requires identical configuration across nodes (wsrep_provider, wsrep_cluster_address, and SST method like rsync or xtrabackup-v2).
Backup and recovery strategies
Choose a backup tool appropriate to dataset size and RTO/RPO:
- mysqldump — good for logical backups of small to medium databases; includes –single-transaction for InnoDB consistency.
- mariabackup — physical, non-blocking backups designed for MariaDB; supports incremental backups and faster restores.
- Point-in-time recovery — enable binary logging and store binlogs off-server to replay transactions since the last full backup.
Connection and client considerations
For remote access, secure connectivity with TLS and tightly control network access via firewall rules. When connecting from applications, use connection pooling and prepared statements to reduce overhead. Configure wait_timeout and interactive_timeout to avoid excessive idle connections consuming resources.
Choosing the right VPS for MariaDB
Database performance hinges on CPU, memory and I/O. For production databases consider the following:
- Use SSD-backed storage with high IOPS for low latency.
- Prefer instances with dedicated CPU and consistent I/O rather than bursty performance profiles.
- Provision sufficient RAM to hold the InnoDB buffer pool for your working set. If running replication or Galera, ensure network latency between nodes is low.
Summary
Installing MariaDB on Ubuntu, CentOS and Fedora is straightforward when you follow distribution-specific repository and package procedures, secure the installation, and tune core parameters for your workload. For production deployments, pay close attention to storage performance, backups, TLS, and regular patching. For HA and scale, consider replication topologies (asynchronous replicas or Galera clusters) and select the VPS plan that provides predictable CPU and I/O characteristics.
For teams looking to deploy MariaDB on reliable VPS infrastructure, consider the hosting options available at VPS.DO. If you need a US-based instance optimized for database workloads, see the USA VPS offering at https://vps.do/usa/.