How to Install MariaDB on Debian 9 Stretch


MariaDB is a fork of the most popular MySQL database management system. It is developed by MariaDB Corporation Ab, led by original developers of MySQL.

MariaDB is fully compatible with MySQL database management system and is now considered as a full drop-in replacement.

Install MariaDB on Debian 9

You can obtain MariaDB packages for Debian 9 from two ways.

  1. Debian repository
  2. Official MariaDB mirror

Install MariaDB from Debian Repository

Installing MariaDB from Debian base repository is a straightforward way, but this may have bit old version of MariaDB.

sudo apt-get update
sudo apt-get -y install mariadb-server mariadb-client

Use mysql_secure_installation to do the initial setup of MariaDB server.

sudo mysql_secure_installation
If you have installed MariaDB from base repository, users can not login to MariaDB as the MariaDB root user from their Unix logins (not applicable if they have sudo access)

Perform below steps to override the above restriction.

Login as MariaDB root user.

$ sudo mysql -u root -p


# mysql -u root -p
No password required

Execute below queries in MariaDB database.

use mysql;
update user set plugin='mysql_native_password' where user='root';
flush privileges; 

Now you can log in as root user (MariaDB root) without any problem.

Install MariaDB from Official MariaDB Mirror

MariaDB offers the repository for MariaDB packages. You can choose any one of the mirrors from the MariaDB download page to download and install it.

Add signing key to your system.

sudo apt-get install software-properties-common dirmngr
sudo apt-key adv --recv-keys --keyserver 0xF1656F24C74CD1D8


Add MariaDB repository using the add-apt-repository command.

sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] stretch main'



You can also manually create a repository file under /etc/apt/sources.list.d/ directory.

sudo nano /etc/apt/sources.list.d/mariadb.list

Place the following entries into the mariadb.list.

deb [arch=amd64,i386,ppc64el] stretch main
deb-src stretch main

Install MariaDB server using the following command.

sudo apt-get update
sudo apt-get install -y mariadb-server mariadb-client

While installing MariaDB, the installer will prompt you to set the password for MariaDB root user.

Access MariaDB

Use the below command to login into MariaDB server.

mysql -u root -p
Password required


Install MariaDB on Debian 9 Stretch - MariaDB Shell
Install MariaDB on Debian 9 Stretch – MariaDB Shell

Control MariaDB service

In case if you want to start/stop the MariaDB you can use the following commands.

sudo systemctl start mariadb
sudo systemctl stop mariadb

Verify whether MariaDB is running or not.

sudo systemctl status mariadb

That’s All.

You might also like