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

How to Use MariaDB on Linux Server in 2026? – (Step by Step Tutorial)

To use MariaDB on a Linux server, install it from your distro’s repositories, start and enable the mariadb service, run mysql_secure_installation to harden access, create a database and a user with least privilege, and connect via the mysql client.

For production, configure backups, remote access, and basic performance tuning. Learning how to use MariaDB on Linux server environments is essential for hosting websites, applications, analytics, and internal tools.

This guide walks you through installation, security, basic SQL operations, remote connections, backups, and performance tuning with practical commands you can copy-paste.

It’s beginner friendly and production aware, based on real world hosting experience.


What is MariaDB and Why Use it on Linux?

MariaDB is a high-performance, open source relational database management system (RDBMS) that’s a drop in replacement for MySQL.

It’s widely used across LAMP/LEMP stacks, supports advanced storage engines, and ships with enterprise grade features for replication, security, and scalability. On Linux servers, it’s stable, fast, and well supported by package managers.

Prerequisites

  • A Linux server (Ubuntu/Debian, Rocky/AlmaLinux/CentOS, RHEL, SUSE, Arch) with sudo access
  • Open ports as needed (3306/TCP for remote access)
  • Basic terminal familiarity
  • Package manager configured and system up to date

Ubuntu / Debian

sudo apt update
sudo apt install mariadb-server mariadb-client
mysql --version

Rocky Linux / AlmaLinux / CentOS / RHEL

# RHEL 8+/Rocky/Alma
sudo dnf install mariadb-server mariadb
# RHEL/CentOS 7 (legacy)
sudo yum install mariadb-server mariadb
mysql --version

openSUSE / SLES

sudo zypper refresh
sudo zypper install mariadb mariadb-client
mysql --version

For newer major versions, you can also use the official MariaDB repository. Always ensure the repo matches your distro version.

Start, Enable, and Verify the Service

sudo systemctl enable --now mariadb
sudo systemctl status mariadb
sudo ss -tulpn | grep 3306   # Confirm listening port
sudo mysqladmin ping

If your distro uses the mysql service name, replace mariadb with mysql. Most modern systems alias it to mariadb.

Secure MariaDB (mysql_secure_installation)

Run the bundled hardening script to set a root password, remove anonymous users, disallow remote root login, and clean up test databases.

sudo mysql_secure_installation
# Steps typically include:
# - Set root password (if prompted)
# - Remove anonymous users
# - Disallow root login remotely
# - Remove test database
# - Reload privilege tables

On some distros, the root user authenticates via the unix_socket plugin. If so, run sudo mysql without a password for root-level access locally.

Connect and Run Basic SQL

# Connect as root (password auth)
mysql -u root -p

# Or, if using unix_socket
sudo mysql
-- Inside the MariaDB shell:
SHOW VARIABLES LIKE 'version%';
CREATE DATABASE appdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- Create least-privilege user for the app
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongP@ss!';
GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;

-- Test access
EXIT;
mysql -u appuser -p -D appdb -e "SHOW TABLES;"

Use utf8mb4 for full Unicode (including emoji) support. Always create a dedicated user per application instead of using root.


Import, Export, and Backups

Logical backups with mysqldump

# Dump a single database
mysqldump -u root -p --routines --triggers --single-transaction appdb > appdb.sql

# Restore
mysql -u root -p appdb < appdb.sql

# Dump all databases
mysqldump -u root -p --all-databases --single-transaction > all.sql

Physical backups with mariabackup (hot backups)

# Install mariabackup if not present (package name may vary by distro)
# Example (Debian/Ubuntu): sudo apt install mariadb-backup

# Create a backup
sudo mariabackup --backup --target-dir=/var/backups/mariadb/$(date +%F) --user=root --password=YOURPASS

# Prepare the backup (roll forward)
sudo mariabackup --prepare --target-dir=/var/backups/mariadb/2025-01-01

# Restore (service must be stopped)
sudo systemctl stop mariadb
sudo mariabackup --copy-back --target-dir=/var/backups/mariadb/2025-01-01
sudo chown -R mysql:mysql /var/lib/mysql
sudo systemctl start mariadb

Schedule backups with cron and test restores periodically. Store copies off-server to meet RPO/RTO goals.


Allow Remote Access (Optional)

Edit bind address and create a remote user

# Edit server config (path may vary)
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf   # Debian/Ubuntu
# or: /etc/my.cnf.d/server.cnf or /etc/my.cnf

# Set to listen on all interfaces or a specific IP
bind-address = 0.0.0.0
# Save file, then restart
sudo systemctl restart mariadb
# Create a remote user (replace 203.0.113.10 with your app server's IP)
sudo mysql -e "CREATE USER 'appuser'@'203.0.113.10' IDENTIFIED BY 'StrongP@ss!';"
sudo mysql -e "GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'203.0.113.10'; FLUSH PRIVILEGES;"

Open the firewall and test

# UFW (Ubuntu)
sudo ufw allow 3306/tcp

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

# Test from remote host
mysql -h your.mariadb.ip -u appuser -p -D appdb -e "SELECT 1;"

For production, use strong passwords, restrict by source IP, and prefer TLS-encrypted connections (ssl_cert, ssl_key, ssl_ca). Avoid remote root logins.


Performance Basics: Safe Defaults That Matter

  • innodb_buffer_pool_size: 50–70% of server RAM (for dedicated DB hosts)
  • innodb_log_file_size: suitable for your workload (often 512M–2G)
  • max_connections: right-size to app concurrency
  • slow_query_log + long_query_time: identify queries to index or optimize
  • tmpdir on fast storage if heavy temp usage
# Example snippet (my.cnf or server.cnf)
[mysqld]
innodb_buffer_pool_size=4G
innodb_log_file_size=1G
max_connections=300
slow_query_log=1
slow_query_log_file=/var/log/mysql/mariadb-slow.log
long_query_time=1

Restart MariaDB after changes and monitor memory utilization. Focus on indexing and query design for the biggest gains.

Monitoring and Logs

  • Service health: systemctl status mariadb, journalctl -u mariadb
  • Runtime: SHOW PROCESSLIST;, SHOW ENGINE INNODB STATUS\G
  • Admin stats: mysqladmin status, mysqladmin variables
  • Slow query log review to optimize indexes and queries

MariaDB vs MySQL (Quick Practical Notes)

  • Compatibility: MariaDB aims to be a drop-in replacement for MySQL, but features diverge at higher versions.
  • Performance/Features: MariaDB offers multiple storage engines and fast improvements; validate compatibility when migrating.
  • Tools: mysql client and mysqldump work similarly; some plugins and auth methods differ.

Troubleshooting Common Issues

Can’t log in as root after install

  • Try socket auth: sudo mysql
  • Check auth plugin: SELECT user, host, plugin FROM mysql.user;
  • Set a password if needed: ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewP@ss!';

Service fails to start

  • Check logs: journalctl -u mariadb -xe
  • Verify data dir permissions: chown -R mysql:mysql /var/lib/mysql
  • Port conflicts: confirm 3306 is free; update port in configs if needed.

Remote connection refused

  • Confirm bind-address allows remote access
  • Ensure firewall opens 3306/TCP
  • Grant privileges to the correct host (IP or %)

Real World Best Practices

  • Use separate users per application with least privileges.
  • Standardize utf8mb4 for new databases and tables.
  • Automate nightly backups and test restores quarterly.
  • Capture slow queries and index iteratively.
  • Keep your OS and MariaDB packages updated with change windows.

Where MariaDB Fits in Your Stack

MariaDB powers CMS platforms (WordPress, Joomla, Drupal), ecommerce (WooCommerce), CRMs, and internal microservices. Pair it with NGINX/Apache and PHP-FPM, Node.js, Python, or Go. For heavy workloads, isolate the DB on its own VM or server and scale reads with replicas.

Managed Option: Focus on Your App, Not the Database

If you’d rather not manage patches, backups, and tuning yourself, YouStable offers optimized VPS and dedicated servers with MariaDB-ready images, 24/7 support, and best-practice hardening. We help you size hardware, secure remote access, and set up automated backups so you can ship features faster.


FAQs

How do I install MariaDB on Ubuntu and secure it?

Run sudo apt update && sudo apt install mariadb-server, then sudo systemctl enable –now mariadb. Secure it with sudo mysql_secure_installation to set root password, remove anonymous users, disable remote root, and reload privileges.

What’s the fastest way to create a database and user?

Connect as root and run: CREATE DATABASE appdb CHARACTER SET utf8mb4; CREATE USER ‘appuser’@’localhost’ IDENTIFIED BY ‘StrongP@ss!’; GRANT ALL PRIVILEGES ON appdb.* TO ‘appuser’@’localhost’; FLUSH PRIVILEGES; Then test with mysql -u appuser -p -D appdb.

How can I allow remote connections safely?

Set bind-address to 0.0.0.0 or the server’s IP, create a user restricted to your app server’s IP, open port 3306 in the firewall, and prefer TLS. Never allow remote root, and avoid using % unless necessary.

What backup method should I use: mysqldump or mariabackup?

Use mysqldump for smaller databases and portability (logical backups). Use mariabackup for large, busy databases requiring hot, consistent physical backups and faster restores. Many teams use both for defense in depth.

Which MariaDB settings should I tune first on a new server?

Start with innodb_buffer_pool_size (50–70% RAM for dedicated DB hosts), enable slow_query_log to find bottlenecks, right-size max_connections to app demand, and ensure reliable backups. Then optimize indexes and queries based on real workload data.

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