How to install MariaDB database server on Ubuntu 18.04

Want to migrate from MySQL to MariaDB? Jack Wallen shows you how to install, secure, and log in to this community-developed fork of MySQL.

Image: Jack Wallen

MariaDB is a database server that many consider to be superior to MySQL. Both are open source. Both are multi-threaded relational databases. And both are used wide-spread. One of the biggest differences between the two is that MariaDB development is far more open and vibrant and offers faster, more transparent security releases. Couple that with the fact that a lot of web-server software titles have migrated to MariaDB, and you have reason enough to make the change. But how do you install MariaDB on Ubuntu Server 18.04? It's actually quite simple. Let me walk you through the process.

What you need

I will assume you already have an instance of Ubuntu Server 18.04 up and running and have access to an account with sudo privileges. That's all you need. Let's install.

Update and upgrade

Open a terminal window. Before we actually run the installation, we're going to update and upgrade the server. Remember this: If the kernel upgrades, you'll need to reboot the server. Because of this, you might want to run the update/upgrade commands at a time when it's okay for the server to be rebooted (if this is a production machine).

SEE: IT pro's guide to working smarter with Linux (Tech Pro Research)

To run the update/upgrade, issue the command:

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

If everything checks out on the list of software to upgrade, type Y and then hit Enter. The update and upgrade will complete, and you're ready to install the database server.


Now let's install. From the same terminal window, issue the command:

sudo apt-get install mariadb-server

Once the installation completes, you can start and enable the service with the commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Securing the installation

At this point, things will start looking very similar to that of MySQL. You'll want to create a password for the MariaDB server root account (and do away with 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 have yet to set one, just hit Enter on your keyboard. You will then be prompted to type (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

Securing your MariaDB installation.

That's it. MariaDB is installed.

One caveat

You know how you're accustomed to gaining access to the MySQL prompt? You'd issue a command like:

mysql -u root -p

After successfully authenticating, you'd find yourself on the database prompt. Try that with MariaDB, and you'll be greeted by an error (Figure B).

Figure B

Figure B

No access for you!

Because of the way MariaDB is hardened, you must access the prompt with the help of sudo, like so:

sudo mysql -u root -p

Type your sudo password, followed by the MariaDB root user password, and you'll find yourself at the MariaDB prompt (Figure C).

Figure C

Figure C

You can finally work with MariaDB.

All there is to it

And that, my friends, is all there is to installing, securing, and logging into the MariaDB database server on Ubuntu 18.04. You should find this database server as easy to use as MySQL.

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website

Editor's Picks

Free Newsletters, In your Inbox