Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 40 ยท Getting Started

Installing MariaDB on Windows, Linux, macOS and Docker

Install MariaDB on Windows, Debian/Ubuntu, macOS or Docker, secure the first run, set the root password, choose a port and character set, and test the connection.

You can learn most SQL in the browser, but sooner or later you want a real server. Installing MariaDB takes a few minutes on any system. This lesson walks through Windows, Linux, macOS and Docker, then covers the first-run security steps and the configuration file. Server commands cannot run in the page, so they appear as read-only blocks, followed by a runnable exercise that checks your understanding of the results.

Choose a version

MariaDB has long-term support (LTS) releases, supported for five years, and shorter rolling releases. For learning and production, pick the newest LTS (for example 11.4 or 11.8 at the time of writing). The version string tells you the line: 11.4.2-MariaDB is the 11.4 series, patch 2.

Windows

  1. Download the MSI installer from the MariaDB downloads page and run it.
  2. Accept the license, and keep MariaDB Server and Client programs selected. HeidiSQL is a handy optional extra.
  3. On the "Default instance properties" page, set a password for the root account. Tick Use UTF8 as default server's character set (it sets utf8mb4) and leave Enable networking on with port 3306.
  4. Finish the wizard. The server is installed as a Windows service named MariaDB.

Open "Services" to start or stop it, or use an administrator terminal:

BAT
net start MariaDB
net stop MariaDB
"C:\Program Files\MariaDB 11.4\bin\mariadb.exe" -u root -p

If port 3306 is already taken, for example by another MySQL install, pick a different port in the wizard (3307, say) and connect with -P 3307.

Debian and Ubuntu

Terminal
sudo apt update
sudo apt install mariadb-server
sudo systemctl enable --now mariadb
sudo systemctl status mariadb

On Red Hat family systems the package is also mariadb-server, managed with dnf. The package starts the service for you. By default root logs in through the Unix socket, so sudo mariadb works without a password, which is deliberate and safe on a single machine.

macOS

Terminal
brew install mariadb
brew services start mariadb
mariadb -u root

Homebrew installs the latest stable release and runs the server as your own user.

Docker

Docker is the cleanest way to keep a throw-away server for practice:

Terminal
docker run --name mydb -e MARIADB_ROOT_PASSWORD=change-me \
  -p 3306:3306 -v mariadb-data:/var/lib/mysql -d mariadb:lts
docker exec -it mydb mariadb -u root -p

The named volume mariadb-data keeps your data when you remove the container. Without it, docker rm deletes everything. Environment variables such as MARIADB_DATABASE, MARIADB_USER and MARIADB_PASSWORD create a database and user at first start.

Securing the first run

New installs are open enough to be a risk if exposed. Run the hardening script:

Terminal
sudo mariadb-secure-installation

It offers to set or switch the root authentication, remove anonymous users, disallow remote root login and drop the test database. Answer yes to all of these on any machine that is not strictly local. Then create a normal account for your applications and do not use root in code:

SQL
CREATE USER 'app'@'localhost' IDENTIFIED BY 'a-long-random-password';
CREATE DATABASE shop CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON shop.* TO 'app'@'localhost';
FLUSH PRIVILEGES;

Users and privileges get their own lesson later in the course.

The configuration file

MariaDB reads option files in order. On Linux the main ones are /etc/mysql/my.cnf and files under /etc/mysql/mariadb.conf.d/; on Windows it is my.ini in the data directory. Options live in sections:

INI
[mariadbd]
port                   = 3306
bind-address           = 127.0.0.1
character-set-server   = utf8mb4
collation-server       = utf8mb4_unicode_ci
innodb_buffer_pool_size = 1G
max_connections        = 150

[client]
default-character-set  = utf8mb4

bind-address = 127.0.0.1 makes the server reachable only from the same machine. Change it only when you really need remote access, and then also restrict users by host and use a firewall. After editing, restart the service.

Check what the server actually uses:

SQL
SHOW VARIABLES LIKE 'character_set_server';
SHOW VARIABLES LIKE 'port';
SHOW GLOBAL STATUS LIKE 'Uptime';

Practice without a server

You can still rehearse the verification habit. A server's information_schema is just a set of tables you query. SQLite exposes a similar catalog called sqlite_master, so you can list what exists in a database the same way:

SQL Listing the objects in a database ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

On MariaDB the equivalent is:

SQL
SELECT table_name, engine, table_rows
FROM information_schema.tables
WHERE table_schema = 'shop'
ORDER BY table_name;

And a stand-in for "does this server have what I expect?" counting the tables of the sample database:

SQL How many tables are there? ยท database: shop

Press Run (or Ctrl + Enter) to see the result here.

Common problems

  • "Can't connect to local MySQL server through socket": the service is not running, or the socket path differs. Start the service and check systemctl status mariadb.
  • "Access denied for user 'root'": on Linux, use sudo mariadb, or create a password-based account.
  • Port in use: change port in the option file or stop the other server.
  • Garbled accents: the server or client is not using utf8mb4.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which release type is best for a long-lived production server?

    LTS releases get bug and security fixes for five years, so you upgrade less often.
  2. 2. What does bind-address = 127.0.0.1 do?

    127.0.0.1 is the loopback address, so only local clients can connect. It is a safe default.
  3. 3. Why mount a volume when running MariaDB in Docker?

    Data in a container's own file system disappears with the container. A volume lives outside it.
  4. 4. What should an application use to connect to the database?

    Least privilege limits the damage of a leaked password or SQL injection bug.

Summary

  • Install the newest LTS release with the MSI installer, apt/dnf, Homebrew or the mariadb Docker image.
  • Run mariadb-secure-installation, then create a normal user instead of using root in applications.
  • Settings live in the [mariadbd] and [client] sections of the option file; prefer utf8mb4 everywhere.
  • SHOW VARIABLES and information_schema let you verify what the server is really doing.

Next: The mariadb client and tools