How to Install MariaDB on Ubuntu 16.04


MariaDB is a fork of the very popular MySQL database management system; it is now considered as a full drop-in replacement for MySQL.

Install MariaDB on Ubuntu 16.04

You can install MariaDB in two ways, using either Ubuntu repository or Official MariaDB mirror.

Install MariaDB from Ubuntu Repository

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

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

Use mysql_secure_installation to secure the installation of MariaDB server.

sudo mysql_secure_installation

Perform below steps only when you need to access MariaDB as MariaDB root user from external machines or other Unix logins, otherwise skip below.

Login as MariaDB root user.

$ sudo mysql -u root -p


# mysql -u root -p
No password required
use mysql;
update user set plugin='mysql_native_password' where user='root';
flush privileges; 

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

Install MariaDB from Official Mirror

MariaDB offers an official installer package for MariaDB; you can choose any one of mirrors from the MariaDB downloads page to download it.

Add public signing key to your system.

sudo apt-get -y install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8

Use add-apt-repository command to add MariaDB repository straight away.

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


If you don’t wish to use the above command, you can manually create and update the MariaDB repository file under /etc/apt/sources.list.d/.

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

Place the following entries into the above file.

deb [arch=amd64,i386] xenial main
deb-src xenial main

Now, install MariaDB using the following command.

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

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

Access MariaDB

To access the MariaDB instance, run the following command on the terminal.

mysql -u root -p

Enter the password of root user that you have set during the installation when prompted.

Once after entering the password, you would get a MariaDB shell.

Install MariaDB on Ubuntu 16.04 - MariaDB Shell
Install MariaDB on Ubuntu 16.04 – MariaDB Shell

Control MariaDB service

In case if you want to start/stop the MariaDB; use the following command.

sudo systemctl start mariadb
sudo systemctl stop mariadb

Run the following command in the terminal to check whether MariaDB is running.

sudo systemctl status mariadb

That’s All.

You might also like

How to Install MariaDB on Ubuntu 16.04