August 21, 2026 · by Alex M.
MariaDB is one of the most widely used open-source relational database management systems. Fully compatible with MySQL and faster in many real-world workloads, it has become the default database engine on most modern Linux distributions. Whether you're running a CMS, an e-commerce platform, or a custom web application on your SSD VPS or NVMe VPS, a properly installed and configured MariaDB instance is a foundational requirement.
This guide walks you through every step — from installation to security hardening to performance tuning — on Ubuntu 22.04 LTS.
MariaDB was forked from MySQL following its acquisition by Oracle. Key advantages include:
Platforms like WordPress, Joomla, Magento, and Laravel work with MariaDB out of the box.
Before you start, make sure you have:
sudo privilegesUpdate the system before proceeding:
sudo apt update && sudo apt upgrade -y
On Ubuntu 22.04, MariaDB is available directly from the official repositories:
sudo apt install mariadb-server mariadb-client -y
Start the service and enable it at boot:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Verify it's running:
sudo systemctl status mariadb
You should see Active: active (running) in the output.
Run the security script immediately after installation. It removes anonymous users, disables remote root login, and drops the test database:
sudo mysql_secure_installation
Recommended answers:
| Prompt | Recommended Answer |
|---|---|
| Switch to unix_socket authentication? | N (if you want password auth) |
| Change the root password? | Y — set a strong password |
| Remove anonymous users? | Y |
| Disallow root login remotely? | Y |
| Remove test database? | Y |
| Reload privilege tables? | Y |
⚠️ Important: Never use the root account for web applications. Always create a dedicated database user.
After securing the installation, connect to the MariaDB shell:
sudo mysql -u root -p
Or, using socket authentication (the Ubuntu default):
sudo mysql
You'll see the MariaDB [(none)]> prompt.
Create a separate user and database for each application:
-- Create the database
CREATE DATABASE myapp_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- Create the user
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
-- Grant privileges
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
-- Apply the changes
FLUSH PRIVILEGES;
Always use utf8mb4 instead of utf8 — it supports the full Unicode character set, including emoji.
The main configuration file is /etc/mysql/mariadb.conf.d/50-server.cnf. Open it:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
[mysqld]
# InnoDB buffer pool — allocate 50–70% of available RAM
innodb_buffer_pool_size = 512M
# One instance per GB of buffer pool
innodb_buffer_pool_instances = 1
# Larger log files = faster write performance
innodb_log_file_size = 128M
# Query cache for repeated reads
query_cache_type = 1
query_cache_size = 64M
query_cache_limit = 2M
# Maximum simultaneous connections
max_connections = 150
# Thread cache
thread_cache_size = 8
# Timeout for idle connections
wait_timeout = 300
interactive_timeout = 300
# Default charset
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
💡 Tip: On a 2 GB RAM VPS, set
innodb_buffer_pool_size = 512M. On a 4 GB VPS, you can safely go up to 1–2 GB.
Restart MariaDB after making changes:
sudo systemctl restart mariadb
By default, MariaDB listens only on 127.0.0.1. If you need remote access (e.g., from a separate application server), update the config:
bind-address = 0.0.0.0
Then create a user scoped to a specific IP address:
CREATE USER 'remote_user'@'192.168.1.100' IDENTIFIED BY 'SecurePassword!';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'remote_user'@'192.168.1.100';
FLUSH PRIVILEGES;
Allow port 3306 only from trusted IPs via UFW:
sudo ufw allow from 192.168.1.100 to any port 3306
For more on VPS firewall management, check the guides on the CLIQHOST blog.
Never skip backups. Create a simple script using mysqldump:
sudo nano /usr/local/bin/backup-mariadb.sh
#!/bin/bash
DATE=$(date +%Y-%m-%d_%H-%M)
BACKUP_DIR="/var/backups/mariadb"
DB_USER="root"
DB_PASS="your_root_password"
mkdir -p $BACKUP_DIR
mysqldump -u $DB_USER -p$DB_PASS --all-databases | gzip > $BACKUP_DIR/all-databases_$DATE.sql.gz
# Delete backups older than 7 days
find $BACKUP_DIR -name "*.sql.gz" -mtime +7 -delete
echo "Backup created: $BACKUP_DIR/all-databases_$DATE.sql.gz"
sudo chmod +x /usr/local/bin/backup-mariadb.sh
Schedule it in crontab to run daily at 02:00:
sudo crontab -e
0 2 * * * /usr/local/bin/backup-mariadb.sh >> /var/log/mariadb-backup.log 2>&1
SHOW VARIABLES LIKE 'innodb_buffer_pool_size';
SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected';
Enable the slow query log in the config file:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 2
Analyse it with:
mysqldumpslow -s t /var/log/mysql/slow-queries.log | head -20
SHOW ENGINE INNODB STATUS\G
MariaDB won't start after a config change:
sudo journalctl -u mariadb -n 50
Look for syntax errors in the .cnf file.
"Too many connections" error: Increase max_connections and verify that your application properly closes database connections after use.
Buffer pool too small: If innodb_buffer_pool_reads is high relative to innodb_buffer_pool_read_requests, increase innodb_buffer_pool_size.
MariaDB is a robust, high-performance database engine suited for any modern web application. Proper installation, immediate security hardening, and InnoDB parameter tuning are what separate a sluggish server from one that handles traffic with ease.
For the best MariaDB experience, pair it with CLIQHOST NVMe VPS hosting — designed for workloads that demand fast disk I/O and consistent performance. If you'd prefer a fully managed environment where the technical heavy lifting is handled for you, explore our server management services.
Ready to get started or not sure which plan fits your project? Contact our team — we're happy to help.
Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.
"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."
"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."
"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."