Most websites and many apps keep their data in a MySQL-compatible database. MariaDB is the version that Ubuntu and Debian ship. This page installs it, creates a database with its own user for your website or app, and shows how to reach it safely from your computer. The commands were tested on Ubuntu 26.04 LTS with MariaDB 11.8; run them as root (connect over SSH).
1. Install MariaDB
apt install mariadb-server systemctl status mariadb
The status shows active (running). MariaDB starts by itself after every reboot. It listens only on 127.0.0.1:3306: programs on the server itself can use it, the internet cannot.
Many older guides tell you to run mariadb-secure-installation next. On Ubuntu and Debian it is not needed: the script itself says MariaDB is secure by default in Debian. The database administrator root has no password and can only log in as the root user of the server; there are no anonymous users and no test database.
2. Log In as Administrator
As root on the server, simply type:
mariadb
The prompt changes to MariaDB [(none)]>. Every command ends with a semicolon. SHOW DATABASES; lists the databases, exit leaves.
3. A Database and a User for Your Website or App
Give every website or app its own database and its own user, which can only use this database. In mariadb, replace shop with your name and choose a strong password:
CREATE DATABASE shop; CREATE USER 'shop'@'localhost' IDENTIFIED BY 'a-strong-password'; GRANT ALL PRIVILEGES ON shop.* TO 'shop'@'localhost';
Your app then uses these settings: host localhost (or 127.0.0.1), port 3306, database shop, user shop and the password. To try them, log in as the new user; -p asks for the password:
mariadb -u shop -p shop
The user shop can create tables in its database, but CREATE DATABASE other ends with Access denied for user 'shop'@'localhost': the user cannot touch other databases.
- A new password for the user:
ALTER USER 'shop'@'localhost' IDENTIFIED BY 'new-password'; - Remove the user and the database with all its data:
DROP USER 'shop'@'localhost';andDROP DATABASE shop;
4. Open the Database From Your Computer
Keep MariaDB closed to the internet and use an SSH tunnel instead. On your computer:
ssh -L 3306:127.0.0.1:3306 root@your-server
As long as this SSH session is open, a database program on your computer, for example HeidiSQL, DBeaver or MySQL Workbench, connects to host 127.0.0.1, port 3306, with the user and password from step 3. If MariaDB also runs on your computer, use another local port, for example -L 13306:127.0.0.1:3306 and port 13306. More about tunnels: Open a Web Page That Listens Only on Your Server: SSH Tunnel.
5. More Memory for a Busy Database
MariaDB keeps the most used data in memory, in the InnoDB buffer pool. By default it is only 128 MB, also on a server with much more RAM. For a busy database, give it more in a file of your own, so that updates of MariaDB do not overwrite it:
nano /etc/mysql/mariadb.conf.d/60-tuning.cnf
[mysqld] innodb_buffer_pool_size = 2G
Then systemctl restart mariadb. Check the value with mariadb -e "SELECT @@innodb_buffer_pool_size/1024/1024"; with 2G it shows 2048 (MB). Leave enough memory for your other programs: on a server that also runs a website, about a quarter to a half of the RAM is a common start.
Good to Know
- The settings are in
/etc/mysql/mariadb.conf.d/. On Ubuntu 26.04, the data is in/var/lib/mariadb; on Debian 13, on older systems and in older guides it is/var/lib/mysql. - If MariaDB does not start, its messages are in
journalctl -u mariadb: Find Errors in the Logs of Your Linux Server: journalctl. - Back up your databases every night: Back Up Your MariaDB or MySQL Databases Every Night.
- Remove MariaDB with
apt purge mariadb-server. The data folder/var/lib/mariadbwith all databases stays on the disk; delete it yourself only if you no longer need any of them.