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

How to Create MariaDB on Linux Server in 2026? – Easy Guide

To create MariaDB on a Linux server, install the MariaDB server package, start and secure the service, then create a database and a user with least-privilege access. On Ubuntu/Debian use APT; on RHEL/AlmaLinux/Rocky use DNF/YUM.

Run mysql_secure_installation, configure networking if needed, enable systemd, and validate with a test connection. If you want to create MariaDB on a Linux server for websites, applications, or analytics, this guide gives you a clean, production-ready path.

We’ll cover installation on Ubuntu/Debian and RHEL based systems, initial security, creating databases and users, performance tuning basics, backups, and common troubleshooting using beginner friendly steps that follow industry best practices.

As a hosting professional, I’ll also show you when it makes sense to use a managed VPS from a provider like YouStable to offload maintenance and focus on your app.

Prerequisites and System Requirements

Before you create MariaDB on a Linux server, make sure you have the following in place:

  • A supported Linux distribution: Ubuntu 20.04/22.04/24.04, Debian 11/12, AlmaLinux/Rocky Linux 8/9, RHEL 8/9
  • Root or sudo access
  • Updated package indexes and system packages
  • Open ports if remote access is required (default TCP 3306)
  • Baseline server sizing: 1–2 vCPU, 2–4 GB RAM for small apps; more for heavy workloads

Install and Configure MariaDBStep by Step

Update the System

# Ubuntu / Debian
sudo apt update && sudo apt -y upgrade

# RHEL / AlmaLinux / Rocky
sudo dnf -y update

Install MariaDB on Ubuntu/Debian (APT)

The fastest path is the distro repository. For newer features, use the official MariaDB repo. Start with the OS repo first:

# Install from Ubuntu/Debian repository
sudo apt -y install mariadb-server mariadb-client

# Start and enable
sudo systemctl enable --now mariadb

# Check status
systemctl status mariadb

To install a specific version (e.g., LTS) from the official MariaDB repository:

# Add the official MariaDB repo (example for Ubuntu 22.04; adjust for your distro)
sudo apt -y install software-properties-common curl gnupg
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash

# Install server and client
sudo apt -y install mariadb-server mariadb-client
sudo systemctl enable --now mariadb

Install MariaDB on RHEL/AlmaLinux/Rocky (DNF/YUM)

Use the OS repository for stability, or the official MariaDB repo for newer versions.

# OS repository (stable)
sudo dnf -y install mariadb-server

# Start and enable
sudo systemctl enable --now mariadb

# Status
systemctl status mariadb

Alternatively, add the official MariaDB repository for a specific major version:

# Add official MariaDB repo
sudo dnf -y install curl
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash

# Install and start
sudo dnf -y install MariaDB-server MariaDB-client
sudo systemctl enable --now mariadb

Secure the Server: mysql_secure_installation

Run the built-in hardening script immediately after installation. It sets the root password, removes test databases, and enforces sane defaults.

sudo mysql_secure_installation

Recommended answers during the prompts:

  • Set root password: Yes
  • Remove anonymous users: Yes
  • Disallow root remote login: Yes (unless you have a strict, secured need)
  • Remove test DB: Yes
  • Reload privilege tables: Yes

Create a Database and a Least-Privilege User

Log into MariaDB and create your application database and user with the minimum privileges required.

# Log in as root (use sudo if required)
sudo mysql -u root -p

# Inside the MariaDB shell:
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'Strong_Passw0rd!';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Test the Connection

mysql -u appuser -p -D appdb -e "SELECT VERSION() AS mariadb_version;"

Enable Remote Access (Optional)

Only open remote access if your app server is separate from the DB server and you have a firewall, strong passwords, and ideally a private network or VPN. Steps:

  • Allow MariaDB to listen on all interfaces or a specific IP
  • Create a user bound to the app server’s IP
  • Open the firewall port securely
# Edit the MariaDB config (path may vary)
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf    # Ubuntu/Debian
# or
sudo nano /etc/my.cnf                                # RHEL-based

# Set
bind-address = 0.0.0.0   # or a specific LAN/VPC IP

# Restart MariaDB
sudo systemctl restart mariadb

# Create a remote user (replace 203.0.113.10 with your app server IP)
sudo mysql -u root -p -e "CREATE USER 'appuser'@'203.0.113.10' IDENTIFIED BY 'Strong_Passw0rd!'; GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'203.0.113.10'; FLUSH PRIVILEGES;"

Open the firewall carefully:

# UFW (Ubuntu)
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp

# firewalld (RHEL/Alma/Rocky)
sudo firewall-cmd --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port protocol="tcp" port="3306" accept' --permanent
sudo firewall-cmd --reload

Start on Boot and Verify

sudo systemctl enable mariadb
sudo systemctl status mariadb
ss -tulpn | grep 3306

Performance Tuning Basics (Safe Defaults)

For small to medium workloads, these baseline tweaks improve performance and consistency. Adjust to your RAM and workload. Put them into a custom config include (preferred) instead of editing the main file.

# Ubuntu/Debian include file
sudo nano /etc/mysql/mariadb.conf.d/60-tuning.cnf

# RHEL-based include file
sudo nano /etc/my.cnf.d/60-tuning.cnf
[mysqld]
# Use UTF-8 everywhere
character-set-server = utf8mb4
collation-server     = utf8mb4_unicode_ci

# InnoDB (transactional engine)
innodb_buffer_pool_size = 1G     # ~50–70% of RAM on a dedicated DB server
innodb_log_file_size    = 256M
innodb_flush_log_at_trx_commit = 1
innodb_file_per_table   = 1

# Connections
max_connections = 200

# Slow query logging
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 1

# Networking
skip_name_resolve = 1
# Apply changes
sudo systemctl restart mariadb

Backups and Restores (Essential)

  • Logical backups: good for portability (mysqldump, mariadb-dump)
  • Physical/hot backups: faster for large datasets (Percona XtraBackup, MariaDB Backup)
  • Automate daily dumps and store off-server (S3/object storage)
# Dump a single database
mysqldump -u root -p --routines --events --single-transaction appdb > /backup/appdb_$(date +%F).sql

# Restore
mysql -u root -p appdb < /backup/appdb_YYYY-MM-DD.sql

# Dump all databases
mysqldump -u root -p --all-databases --single-transaction --routines --events > /backup/all_$(date +%F).sql

Monitoring and Logs

  • Service logs: journalctl -u mariadb
  • Error log: /var/log/mysql/error.log (Ubuntu/Debian) or /var/log/mysqld.log (RHEL-based)
  • Slow queries: /var/log/mysql/mariadb-slow.log (as configured)
  • Health checks: SHOW GLOBAL STATUS, information_schema tables
# Basic health snapshot
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Threads_connected'; SHOW GLOBAL STATUS LIKE 'Uptime'; SHOW GLOBAL VARIABLES LIKE 'version';"

Common Errors and Fixes

  • Can’t connect to local MySQL server through socket: Ensure the service is running (systemctl status mariadb) and your client points to the correct socket (/var/run/mysqld/mysqld.sock).
  • Access denied for user: Verify user host portion (e.g., ‘appuser’@’localhost’ vs ‘appuser’@’%’), reset password if needed, and FLUSH PRIVILEGES.
  • Port 3306 not listening: Check bind-address and firewalls; restart MariaDB and verify with ss -tulpn.
  • Out of memory or slow performance: Increase innodb_buffer_pool_size, review slow query log, and add indexes.
  • Upgrade conflicts: If switching from distro to official repo, fully remove old packages (keeping data dir), clear caches, then install the desired version.

Real World Tips from Production

  • Use utf8mb4 by default to avoid emoji and multilingual text issues.
  • Keep app and DB on separate servers or networks for better security and performance.
  • Restrict remote DB access to fixed IPs and use VPN or private subnets in cloud environments.
  • Run regular slow query reviews; most performance wins come from better indexes and queries.
  • Automate nightly backups and test restores monthly.

When to Use a Managed VPS (YouStable)

If managing patches, backups, and tuning feels heavy, a managed VPS from YouStable can help. We provision MariaDB with secure defaults, continuous monitoring, snapshots, and 24/7 support. That means you focus on your app while we handle uptime, optimization, and incident response. Ask our team to pre-size your buffer pool and storage for your workload.

FAQ’s

1. How do I install MariaDB on Ubuntu, Debian, or RHEL?

On Ubuntu/Debian: sudo apt install mariadb-server. On RHEL/Alma/Rocky: sudo dnf install mariadb-server. For newer features, add the official MariaDB repository via the mariadb_repo_setup script, then install and enable the service with systemd.

2. How do I secure MariaDB after installation?

Run mysql_secure_installation, set a strong root password, remove anonymous users and test databases, disallow remote root login, and enable a firewall. Use least-privilege database users for each application and rotate credentials periodically.

3. How do I create a database and user in MariaDB?

Log in as root and run: CREATE DATABASE appdb CHARACTER SET utf8mb4; CREATE USER ‘appuser’@’localhost’ IDENTIFIED BY ‘pass’; GRANT ALL PRIVILEGES ON appdb.* TO ‘appuser’@’localhost’; FLUSH PRIVILEGES;. Replace names and passwords appropriately.

4. How can I enable remote access safely?

Set bind-address to 0.0.0.0 or a specific private IP, create a user with a fixed source IP (e.g., ‘appuser’@’203.0.113.10’), and allow port 3306 from that IP in your firewall. Prefer private networking or a VPN to avoid exposing the database to the public internet.

5. Is MariaDB a drop-in replacement for MySQL?

For most common LAMP/LEMP workloads, yes—MariaDB is highly compatible with MySQL clients and SQL syntax. Advanced features and edge cases can differ between versions. Always test your application, especially if you rely on specific MySQL plugins or newer features.

By following these steps, you’ll reliably create MariaDB on a Linux server, secure it, and keep it performing well. When you’re ready to scale or prefer hands-off management, YouStable can provision and optimize a managed MariaDB environment tailored to your application.

Sanjeet Chauhan

Sanjeet Chauhan is a blogger & SEO expert, dedicated to helping websites grow organically. He shares practical strategies, actionable tips, and insights to boost traffic, improve rankings, & maximize online presence.

Leave a Comment

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

Scroll to Top