How to Install MariaDB on Ubuntu

Filed Under: Ubuntu
Install Mariadb On Ubuntu

We can install MariaDB on Ubuntu from the Ubuntu repositories or the official MariaDB repositories. In this tutorial, we’ll go over both the methods in detail.

The preferred way is to make use of the Ubuntu repositories but if you want to download packages that are compiled by MariaDB, then you can the MariaDB repository.

What is MariaDB?

MariaDB is an open-source, community-supported fork of the MySQL relational database system. It is also backward compatible with the MySQL server, so any scripts you’ve written with MySQL in mind will work with MariaDB.

MariaDB can be used in a wide array of applications including but not limited to banking and websites to turn data into structured information.

How to Install MariaDB on Ubuntu?

We’ll first go over the steps to install MariaDB in Ubuntu using the Ubuntu repository.

1. Install MariaDB Using Ubuntu Repositories

Ubuntu gives us access to a pre-compiled package for MariaDB which is accessible through the apt repositories without any configuration. Let’s run the below commands to update the repository index.

root@ubuntu:~# apt update
Update Ubuntu Packages Using Apt
Update Ubuntu Packages Using Apt

Once the repositories are updated, we will move on to installing the mariadb-server package.

root@ubuntu:~# apt install mariadb-server
Install Mariadb Server Using Apt
Install MariaDB Server Using Apt

This would take some time depending on the speed of your internet. But once done, you will have a MariaDB server installed in your system.

We will check the service status of the MariaDB server to check if it’s running, and start the service if it isn’t already.

root@ubuntu:~# service mariadb status
Service Mariadb Status Output
Service MariaDB Status Output

If you receive the above output stating that the service is active, you’ve successfully installed MariaDB in your system and can verify this by typing one of the below commands.

root@ubuntu:~# mariadb -V
root@ubuntu:~# mysql -V

The reason why it works with both the commands brings us back to what we discussed at the beginning of this tutorial.

The MariaDB server was made to be backward compatible with MySQL. So any scripts that you’ve written for MySQL should work with MariaDB.

If you do not see the MariaDB service status as active, you can activate it by using the following command.

root@ubuntu:~# service mariadb start

2. Installing MariaDB Using MariaDB Repositories

To install MariaDB on Ubuntu, we’ll first visit the MariaDB repositories page and select the Linux distribution that we’re working with. In this case, it’s Ubuntu 19.10 “eoan”.

Now, we download the software-properties-common package which allows us to easily add, manage, and remove apt repositories from multiple independent software vendors.

root@ubuntu:~# apt install software-properties-common

2.1) Importing Public Key and Adding MariaDB Sources

Once installed, we’ll move on to adding the public keys required to access the MariaDB repositories and download packages from there.

The below line can have a different key-value depending on the distribution you’re working with.

root@ubuntu:~# apt-key adv --recv-keys --keyserver hkp:// 0xF1656F24C74CD1D8
Import Mariadb Public Keys
Import MariaDB Public Keys

Now, we’ll add the official MariaDB repositories to our sources list using the command below.

root@ubuntu:~# add-apt-repository 'deb [arch=amd64] eoan main'
Add MariaDB Apt Repositories
Add MariaDB Apt Repositories

2.2) Alternative – Manually Adding MariaDB Sources

If you do not wish to download an additional package to add sources, you can manually add MariaDB sources at the end of the /etc/apt/sources.list file.

Open the file in your favorite text editor, and paste the two lines at the end of the file.

deb [arch=amd64] eoan main
deb-src eoan main
Manually Add Mariadb Repositories In Sources
Manually Add MariaDB Repositories In Sources

2.3) Updating Sources and Installing MariaDB

Now comes the easy part. You’ve added the sources and imported the keys. All we need to do now is to install MariaDB.

root@ubuntu:~# apt update
root@ubuntu:~# apt install mariadb-server

If all went well, you should have the MariaDB server installed in your system.

2.4) Checking MariaDB Installed Version

You can check the installed version with either of the commands below. Both of the commands will give you the MariaDB version that’s installed in your system.

root@ubuntu:~# mariadb -V
root@ubuntu:~# mysql -V
Checking Mariadb Installation Version
Checking MariaDB Installation Version

Logging Into MariaDB

Similar to how the MariaDB and MySQL commands were used interchangeably above, we can log in to the MariaDB server using either of the commands.

root@ubuntu:~# mysql -u root
root@ubuntu:~# mariadb -u root
Login To Mariadb Server
Login To MariaDB Server


In this tutorial, we covered how to install MariaDB in Ubuntu. After following all the steps, you should have a working installation of the MariaDB server on your system.

Also, if you’re interested in setting up WordPress on your Ubuntu system, don’t forget to check out our tutorial on installing WordPress with Nginx on Ubuntu.

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors