MariaDB is a drop‑in replacement for MySQL, offering better performance and open‑source licensing. This guide walks you through installing and securing MariaDB on Ubuntu 24.04.
Prerequisites
A VPS running Ubuntu 24.04 (check our VPS reviews). SSH access and basic command line knowledge.
Step 1: Install MariaDB
sudo apt update
sudo apt install mariadb-server -y
Step 2: Secure the Installation
sudo mysql_secure_installation
Follow the prompts: set root password, remove anonymous users, disable remote root login, remove test databases.
Step 3: Test MariaDB
sudo systemctl status mariadb
Log in to test:
sudo mysql -u root -p
Show databases:
SHOW DATABASES;
EXIT;
Step 4: Create a Database and User
Log in as root:
sudo mysql -u root -p
Create a database:
CREATE DATABASE myapp_db;
Create a user and grant privileges:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Step 5: Allow Remote Access (Optional)
Edit the MariaDB config file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Change the bind‑address line:
bind-address = 0.0.0.0
Then restart MariaDB:
sudo systemctl restart mariadb
Create a user that can connect from any IP:
CREATE USER 'myuser'@'%' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myuser'@'%';
FLUSH PRIVILEGES;
Security note: Only allow remote access if necessary, and restrict IPs via firewall.
Step 6: Basic MariaDB Commands
# List all databases
SHOW DATABASES;
# Select a database
USE myapp_db;
# List tables
SHOW TABLES;
# Show table structure
DESCRIBE table_name;
# Backup database
mysqldump -u root -p myapp_db > backup.sql
# Restore database
mysql -u root -p myapp_db < backup.sql
Troubleshooting
Can't connect to MariaDB – Check if the service is running: sudo systemctl status mariadb.
Access denied for user – Verify username, password, and host privileges.
Next Steps
Now you have a MariaDB server running. You can connect it to web applications like WordPress, Laravel, or custom scripts.