For our Blog Visitor only Get Additional 3 Month Free + 10% OFF on TriAnnual Plan YSBLOG10
Grab the Deal

How to Install MariaDB on Linux Server: Step-by-Step Guide (2026)

To install MariaDB on a Linux server, update your packages, add the official MariaDB repository (optional), install the mariadb-server package with your distro’s package manager, enable and start the service, run mysql_secure_installation to harden, then create a database and user. Commands differ slightly on Ubuntu/Debian, RHEL/Rocky, SUSE, and Amazon Linux.

Installing MariaDB on a Linux server is straightforward and gives you a fast, open-source relational database compatible with MySQL. This guide explains step-by-step installation for major distributions, security hardening, remote access, performance tuning, backups, and troubleshooting—written from real-world server experience so you can go from zero to production-ready confidently.

What Is MariaDB And Why Install It On Linux?

How to Install MariaDB on Linux Server: Step-by-Step Guide (2026)

MariaDB is a drop-in replacement for MySQL developed by the original MySQL creators. It’s known for reliability, performance, and an open governance model. On Linux, it integrates cleanly with systemd, package managers, and security frameworks (SELinux/AppArmor), making it the default database choice for many web apps, CMSs (including WordPress), and analytics workloads.

Prerequisites

Before you begin, ensure:

  • Supported Linux distro (Ubuntu/Debian, RHEL/Rocky/AlmaLinux, SUSE, Amazon Linux)
  • Root or sudo access
  • Outbound internet access (to fetch packages)
  • Open TCP port 3306 if remote clients will connect

Choose Your Install Source: Distro Repo vs MariaDB Repository

You can install MariaDB from your distribution’s repository (stable, tightly integrated) or from the official MariaDB Repository (newer features and LTS lines such as 10.11/11.4). For most users, distro packages are fine; for advanced features or newer versions, use the MariaDB repo.

Install MariaDB On Major Linux Distributions

Ubuntu 22.04/24.04 and Debian 11/12 (Distro Packages)

sudo apt update
sudo apt install -y mariadb-server
sudo systemctl enable --now mariadb
sudo mysql_secure_installation
mariadb --version

Tip: On Ubuntu/Debian, the root database account often uses unix_socket authentication. Use sudo mariadb to log in as root without a password.

Ubuntu/Debian (MariaDB Official Repository)

sudo apt update
sudo apt install -y curl ca-certificates gnupg
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo apt update
sudo apt install -y mariadb-server
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

RHEL 8/9, Rocky Linux, AlmaLinux (Distro or MariaDB Repo)

# Option A: MariaDB official repository
sudo dnf install -y curl
curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo dnf install -y MariaDB-server MariaDB-client

# Option B: Distro-provided packages (names may vary)
# sudo dnf install -y mariadb-server

sudo systemctl enable --now mariadb
sudo mysql_secure_installation
mariadb --version

Amazon Linux 2/2023

# Amazon Linux 2
sudo yum install -y mariadb-server
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

# Amazon Linux 2023 (dnf)
# sudo dnf install -y mariadb-server
# sudo systemctl enable --now mariadb
# sudo mysql_secure_installation

openSUSE/SLES

sudo zypper refresh
sudo zypper install -y mariadb
sudo systemctl enable --now mariadb
sudo mysql_secure_installation

Secure The Installation

mysql_secure_installation helps remove unsafe defaults and set authentication options. During prompts, choose strong settings.

  • Remove anonymous users
  • Disallow remote root login
  • Remove test database
  • Reload privilege tables

If your distro uses unix_socket for root (Ubuntu/Debian), prefer creating a separate admin user rather than changing root auth:

sudo mariadb
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'Strong!Passw0rd';
GRANT ALL PRIVILEGES ON *.* TO 'dbadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Create A Database And App User

sudo mariadb
CREATE DATABASE appdb DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'%' IDENTIFIED BY 'Another$trongP@ss';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'%';
FLUSH PRIVILEGES;

Using % allows connections from any host. For tighter security, replace % with a specific IP or subnet (for example, ‘appuser’@’192.0.2.%’).

Allow Remote Connections (Optional)

For remote access, configure MariaDB to listen on the network interface and open firewalls. Only enable this if needed; otherwise, keep it local for better security.

1) Bind Address

Edit the server configuration (path depends on distro):

  • Debian/Ubuntu: /etc/mysql/mariadb.conf.d/50-server.cnf
  • RHEL/Rocky/AlmaLinux: /etc/my.cnf.d/server.cnf or /etc/my.cnf
[mysqld]
bind-address = 0.0.0.0
port = 3306

Then restart:

sudo systemctl restart mariadb

2) Open The Firewall

# UFW (Ubuntu)
sudo ufw allow 3306/tcp

# firewalld (RHEL/Rocky/AlmaLinux)
sudo firewall-cmd --add-service=mysql --permanent
sudo firewall-cmd --reload

SELinux: Default port 3306 is allowed. If you change the port, label it:

sudo semanage port -a -t mysqld_port_t -p tcp 3307
sudo systemctl restart mariadb

Service Management And Logs

# Service control
sudo systemctl status mariadb
sudo systemctl restart mariadb
sudo systemctl enable --now mariadb

# Logs (vary by distro)
# Debian/Ubuntu
sudo tail -n 100 /var/log/mysql/error.log
# RHEL/Rocky/AlmaLinux
sudo tail -n 100 /var/log/mariadb/mariadb.log
# Journal
sudo journalctl -u mariadb --no-pager -e

Performance Tuning Essentials

Start with sensible defaults, then tune iteratively based on workload and metrics. Edit your main server config and restart.

  • innodb_buffer_pool_size: If MariaDB is dedicated, set to ~50–70% of RAM.
  • innodb_flush_log_at_trx_commit: 1 for full durability (default), 2 for better performance with slightly less durability.
  • max_connections: Size to expected concurrency (for example, 200); ensure OS and hardware can handle it.
  • tmp_table_size and max_heap_table_size: Increase to reduce on-disk temp tables (keep values equal).
  • slow query log: Enable to catch problematic queries and add indexes where needed.
[mysqld]
innodb_buffer_pool_size = 4G
innodb_flush_log_at_trx_commit = 1
max_connections = 200
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1

Note: MariaDB retained the old Query Cache longer than MySQL, but it’s not recommended for modern workloads. Focus on indexes, schema, and buffer sizing instead.

Backups And Restore (Practical Options)

For small-to-medium databases and simple workflows, mysqldump is easy and reliable. For large, hot backups, consider mariabackup (hot physical backup tool from MariaDB).

Logical Backup With mysqldump

# Single database (consistent InnoDB snapshot)
mysqldump -u root -p --single-transaction --routines --triggers appdb > appdb_$(date +%F).sql

# All databases
mysqldump -u root -p --single-transaction --routines --triggers --events --all-databases > full_$(date +%F).sql

Restore

mysql -u root -p appdb < appdb_2025-01-01.sql
# Or for full dump:
mysql -u root -p < full_2025-01-01.sql

Troubleshooting Common Issues

“Access denied for user ‘root’@’localhost’”

On Ubuntu/Debian, use sudo mariadb to log in as root via socket auth. If you need a passworded root or a new admin user, create it as shown above.

“Can’t connect to local MySQL server through socket”

  • Check service: sudo systemctl status mariadb
  • Verify socket path matches the client config (for example, /var/run/mysqld/mysqld.sock)
  • Review error logs for crashes or permission problems

Reset Root Password (Emergency)

sudo systemctl stop mariadb
sudo mysqld_safe --skip-grant-tables --skip-networking &
# In another terminal:
mariadb
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'New!SuperSecurePass';
FLUSH PRIVILEGES;
# Stop the safe server and start normally
sudo pkill -f mysqld_safe
sudo pkill -f mysqld
sudo systemctl start mariadb

Production Hardening Checklist

  • Disable or remove any ‘root’@’%’ accounts; never expose root remotely.
  • Grant least privilege to app users (only the specific database, no global admin).
  • Restrict network access to trusted hosts and subnets; use firewalls and security groups.
  • Enforce strong passwords and consider PAM/LDAP integration if needed.
  • Enable regular backups and test restores.
  • Monitor with metrics and logs (Prometheus exporters, slow log analysis).
  • Keep OS and MariaDB patched; schedule maintenance windows.

Upgrade And Uninstall

Upgrade

# Ubuntu/Debian (distro repo or MariaDB repo)
sudo apt update
sudo apt install -y mariadb-server

# RHEL/Rocky/AlmaLinux
sudo dnf upgrade -y MariaDB-server MariaDB-client

# After package upgrade
sudo systemctl restart mariadb
mariadb --version

Uninstall (with caution)

# Ubuntu/Debian
sudo apt remove --purge -y mariadb-server mariadb-client
sudo rm -rf /var/lib/mysql /etc/mysql

# RHEL/Rocky/AlmaLinux
sudo dnf remove -y MariaDB-server MariaDB-client
sudo rm -rf /var/lib/mysql /etc/my.cnf /etc/my.cnf.d

Always back up data before removing packages or directories.

Real-World Tips From Hosting

  • Use utf8mb4 across the board for correct Unicode support (emojis, multi-language).
  • Separate data from the OS disk for performance and easier migration; ensure correct ownership and SELinux/AppArmor contexts.
  • Benchmark changes (sysbench) before/after tuning to avoid regressions.
  • For WordPress, optimize indexes on wp_options autoloaded rows and keep plugins lean.
  • Consider high availability with Galera Cluster when you need writes on multiple nodes.

If you prefer expert-managed setup, YouStable’s managed VPS and dedicated servers can provision, secure, and monitor MariaDB for you—so you focus on your application while we handle uptime, backups, and scaling.

FAQs: Install MariaDB On Linux Server

Which MariaDB version should I install?

Use your distro’s default for stability or the MariaDB Repository for newer features. Prefer an active LTS branch (for example, 10.11 or 11.4 at the time of writing) for long-term support in production.

How do I allow remote connections safely?

Set bind-address = 0.0.0.0 (or a specific IP), create users restricted by host/IP, and open only necessary firewall rules. Consider VPN or SSH tunnels for administrative access and never expose root remotely.

What’s the difference between MariaDB and MySQL?

MariaDB is a community-driven fork of MySQL with compatible client/server protocols and tools. It includes additional engines and features and follows an open development model. Many apps work interchangeably, but always test for version-specific features or syntax differences.

How do I back up MariaDB on a schedule?

Use mysqldump in a cron job for logical backups or mariabackup for hot physical backups. Store backups off-server, encrypt them, and test restores regularly to validate recovery time and integrity.

Is MariaDB good for WordPress and eCommerce?

Yes. MariaDB powers millions of WordPress and WooCommerce sites. Use utf8mb4, enable slow query logging, keep plugins lean, and size innodb_buffer_pool appropriately. Consider read replicas or a Galera cluster as traffic grows.

Conclusion

You’ve learned how to install MariaDB on a Linux server, lock it down, enable remote access, tune performance, and set up backups. Start with the distro packages for simplicity or use the MariaDB repo for newer LTS features. If you want a hands-free, optimized setup, YouStable can manage, monitor, and scale MariaDB for you.

Share via:

Prahlad Prajapati

Prahlad is a web hosting specialist and SEO-focused organic growth expert from India. Active in the digital space since 2019, he helps people grow their websites through clean, sustainable strategies. Passionate about learning and adapting fast, he believes small details create big success. Discover his insights on web hosting and SEO to elevate your online presence.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top