How to install MariaDB database server on Ubuntu 18.04

Do you want to migrate from MySQL to MariaDB? Jack Wallen shows you how to install, secure and connect to this community-developed fork of MySQL.

Image: Jack Wallen

MariaDB is a database server that many consider superior to MySQL. Both are open source. Both are multithreaded relational databases. And both are widely used. One of the biggest differences between the two is that the development of MariaDB is much more open and dynamic and offers faster and more transparent security versions. Add to that the fact that many web server software titles have migrated to MariaDB, and you have enough reasons to make the switch. But how to install MariaDB on Ubuntu Server 18.04? It’s actually quite simple. Let me walk you through the process.

What do you need

I’m assuming you already have a working Ubuntu Server 18.04 instance and have access to an account with sudo privileges. This is all you need. Let’s install.

Update and upgrade

Open a terminal window. Before starting the installation, we will update and upgrade the server. Remember this: if the kernel is upgraded, you will need to restart the server. For this reason, you may want to run the update / upgrade commands at a time when restarting the server is acceptable (if it is a production machine).

SEE: IT Professional’s Guide to Working Smarter with Linux (Tech Pro Research)

To run the update / upgrade, run the command:

sudo apt-get update && sudo apt-get upgrade

If everything is correct in the list of software to upgrade, type Y, and then press Enter. The update and upgrade is complete and you are ready to install the database server.


Now let’s install. From the same terminal window, run the command:

sudo apt-get install mariadb-server

Once the installation is complete, you can start and activate the service with the commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Securing the installation

At this point, things will start to look a lot like MySQL. You’ll want to create a password for the MariaDB server root account (and remove some of the defaults). This is handled with the command:

sudo mysql_secure_installation

This will first ask you to enter the password for the root user. Since you haven’t defined one yet, just hit Enter on your keyboard. You will then be prompted to enter (and verify) a new password for the root user. Once you’ve created the password, accept the default for the remaining questions (Figure A).

Figure A

Figure A

Secure your MariaDB installation.

That’s it. MariaDB is installed.


Do you know how you used to access the MySQL prompt? You would issue a command like:

mysql -u root -p

After successfully authenticating, you would end up at the database prompt. Try this with MariaDB, and you will be greeted with an error (Number B).

Number B

Number B

Due to the way MariaDB is hardened, you need to access the prompt using sudo, as follows:

sudo mysql -u root -p

Type your sudo password, followed by the MariaDB root user password, and you will end up at the MariaDB prompt (Figure C).

Figure C

Figure C

You can finally work with MariaDB.

All there is to do

There you have it, my friends, all you need to do to install, secure and connect to the MariaDB database server on Ubuntu 18.04. You should find this database server as easy to use as MySQL.

Maria H. Underwood