Intermediate · 14 min · practise every command in the built-in terminal

MariaDB — Your First Database

Shops, blogs, booking systems: their data lives in a database. On Debian that's usually MariaDB — MySQL's community version, with the same commands and the same SQL.

sudo apt install mariadb-server
systemctl status mariadb
● mariadb.service - MariaDB 11.8.6 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: enabled)
     Active: active (running) since Sun 2026-11-01 15:37:12 CET; 5s ago
     Status: "Taking your SQL requests now..."

It started by itself, and listens only on 127.0.0.1:3306 — this server, not the internet.

Logging in

sudo mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 31
Server version: 11.8.6-MariaDB-0+deb13u1 from Debian

MariaDB [(none)]>

No password: MariaDB's root is the system's root (unix_socket) — sudo is the key. Without it:

mariadb
ERROR 1045 (28000): Access denied for user 'student'@'localhost' (using password: NO)

At the MariaDB [(none)]> prompt you type SQL, each statement ended by ; — exit leaves. -e runs a statement straight from the shell:

sudo mariadb -e "SHOW DATABASES"
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Those four are MariaDB's own. Now yours:

A database and a table

sudo mariadb -e "CREATE DATABASE shop"
sudo mariadb shop -e "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT NULL, price DECIMAL(6,2))"
sudo mariadb shop -e "DESCRIBE products"
ColumnTypeMeans
idINT AUTO_INCREMENT PRIMARY KEYa number MariaDB gives every row: 1, 2, 3…
nameVARCHAR(100) NOT NULLtext up to 100 characters — required
priceDECIMAL(6,2)money: exactly 2 decimals

The shop after mariadb picks the database; at the prompt that's USE shop;.

Rows in, rows out

sudo mariadb shop -e "INSERT INTO products (name, price) VALUES ('Espresso', 1.80), ('Cappuccino', 2.60), ('Latte', 2.90)"
sudo mariadb shop -e "SELECT * FROM products"
+----+------------+-------+
| id | name       | price |
+----+------------+-------+
|  1 | Espresso   |  1.80 |
|  2 | Cappuccino |  2.60 |
|  3 | Latte      |  2.90 |
+----+------------+-------+

More SQL to try:

SELECT name, price FROM products WHERE price < 2.70 ORDER BY price;
SELECT COUNT(*), AVG(price) FROM products;
UPDATE products SET price = 2.00 WHERE name = 'Espresso';
DELETE FROM products WHERE id = 3;

⚠️ UPDATE and DELETE without WHERE change every row. Write the WHERE first.

💡 Into a pipe or a file (| grep, > out.txt) mariadb writes tab-separated lines instead of the table — easy for scripts. -N leaves out the column names.

Practice tasks

  1. Install MariaDB
  2. Check that it runs
  3. List the databases
  4. Create a database: shop
  5. Create the table products in it
  6. Put three products in
  7. Show only the products under 2.70

Commands in this lesson

Databases (MariaDB)