Tech News

How to Install MariaDB on Debian 9

MariaDB is an open-source multi-threaded relational database management system, a backward compatible replacement for MySQL. It is maintained and developed by the MariaDB Foundation, including some of the original MySQL developers.

With the release of Debian 9, MySQL was replaced by MariaDB as the default database system.

In this tutorial, we are going to show you two different methods to install MariaDB on your Debian 9 machine. The first method will guide you through the steps required to install MariaDB from the Debian repositories while the second will teach you how to install the latest version of MariaDB from the official MariaDB repositories.

Generally it is recommended to install MariaDB from the Debian repositories.

If you prefer MySQL to MariaDB, see the tutorial How to Install MySQL on Debian 9. If your application doesn’t have specific requirements, you should stick with MariaDB, the default database system in Debian 9.


Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges.

Install MariaDB on Debian 9

As of this writing, the latest version of MariaDB available in the mainline Debian release is 10.1.

To install MariaDB on Debian 9, follow these steps:

Start by updating theaptpackage index by typing:

sudo apt update

Once the list of packages is updated, install MariaDB by running the following command:

sudo apt install mariadb-server

The MariaDB service will start automatically. You can verify this by typing:

sudo systemctl status mariadb

The output should look like this:

● mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset
Active: active (running) since Wed 2018-09-12 15:10:40 UTC; 1min 48s ago
Main PID: 11356 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
        └─11356 /usr/sbin/mysqld

Installing MariaDB on Debian 9 from MariaDB repositories

As of this writing, the latest version of MariaDB is 10.3 which can be installed from the official MariaDB repositories. Before proceeding to the next step, visit the page of the MariaDB repository and check if a new version is available.

To install MariaDB 10.3 on your Debian 9 system, follow these steps:

1. The first step is to enable the MariaDB repository and import the GPG key from the repository to your system to do this, run the following commands:

sudo apt install software-properties-common dirmngr
sudo apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el]  stretch main'

2. Once the repository is activated, update the list of packages and install MariaDB with:

sudo apt update
sudo apt install mariadb-server

3. The MariaDB service will start automatically, to check it run the following command:

sudo systemctl status mariadb
● mariadb.service - MariaDB 10.3.8 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
Active: active (running) since Sun 2018-07-29 19:36:30 UTC; 56s ago
    Docs: man:mysqld(8)
Main PID: 16417 (mysqld)
Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 507)
CGroup: /system.slice/mariadb.service
        └─16417 /usr/sbin/mysqld

Securing MariaDB

To improve the security of the MariaDB installation, run the mysql_secure_installationscript:

sudo mysql_secure_installation

The script will ask you to set a password for the root account, remove the anonymous user, restrict the root user’s access to the local machine, and remove the test database.

Upon completion, the script will reload the privilege tables ensuring that all changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (Yes) to all questions.

Connect to MariaDB from the command line

To connect to the MariaDB server via the terminal as the root account, type:

mysql -u root -p

You will be prompted to enter the root password that you previously set up using the mysql_secure_installationscript.

Once you enter the password, you will be presented with the MariaDB shell as shown below:

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 2
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>


In this tutorial, we showed you how to install and secure MariaDB on a Debian 9 server. If you have any questions or suggestions, let us know in the comments. Also consult this guide if you want to learn how to install and configure phpMyAdmin on Debian 9.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button