Disclosure: this page contains affiliate links. If you buy through them we may earn a commission at no extra cost to you.

Most self-hosted apps need a database. MariaDB is a drop-in MySQL replacement and the default on Ubuntu — here’s how to install and lock it down.

Step 1: Install MariaDB

sudo apt update
sudo apt install -y mariadb-server

For MySQL specifically, use mysql-server instead.

Step 2: Run the security script

sudo mysql_secure_installation

Set a root password, remove anonymous users, and disable remote root login.

Step 3: Create a database and user

sudo mariadb
CREATE DATABASE myapp;
CREATE USER 'myapp'@'localhost' IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON myapp.* TO 'myapp'@'localhost';
FLUSH PRIVILEGES;

Step 4: Tune for your RAM

Databases grow to fill memory. Give MariaDB about half your VPS RAM via innodb_buffer_pool_size, and enable the slow query log to find bottlenecks.

A 2 GB VPS runs MySQL or MariaDB comfortably for small and medium apps. RackNerd’s 2 GB plan at $35.99/yr gives you full root and a dedicated IPv4.

See RackNerd's current deals