How to Install MariaDB on Ubuntu 18.04
MariaDB is a free and open-source relational database system, that has come to be one of the most popular and widely used in the world.
Development is lead by some of the original developers of MySQL, who forked MariaDB from MySQL in 2009, due to concerns over MySQL’s acquisition by Oracle Corporation.
MariaDB is currently developed and maintained by the MariaDB Foundation and is a drop-in replacement for MySQL. Prominent users of MariaDB include Mozilla, Google and the Wikimedia Foundation, who have switched to it since 2013.
In this tutorial we’ll install MariaDB on an Ubuntu 18.04 machine using two methods:
- The first installation method will be installing MariaDB from the Ubuntu repositories.
- The second method will be installing MariaDB from the official MariaDB repositories.
Table of Contents
Prerequisites
- We recommend that you use a non-root
sudo user
when making major changes to your system. If you don’t have one set up, you can follow our tutorial on creating a sudo user on Ubuntu.
Looking for a new Laptop?
Laptops with Thunderbolt 3 are future proof!
Method 1 – Installing MariaDB from the Ubuntu Repositories
To install MariaDB from the Ubuntu Repositories we’ll just have to update our package index, and then install mariadb-server
To do so, run the following commands:
$ sudo apt update
$ sudo apt install mariadb-server
Now that MariaDB is installed, we can check the status to be sure the installation was successful.
$ sudo systemctl status mariadb
The output should look something like this.
● mariadb.service - MariaDB 10.1.34 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2019-01-06 08:40:29 PST; 3min 30s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 12453 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 28 (limit: 2269)
CGroup: /system.slice/mariadb.service
└─12453 /usr/sbin/mysqld
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: mysql
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: performance_schema
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: Phase 6/7: Checking and upgrading tables
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: Processing databases
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: information_schema
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: performance_schema
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12487]: OK
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12544]: Checking for insecure root accounts.
Jan 06 08:40:31 dracula.host /etc/mysql/debian-start[12548]: Triggering myisam-recover for all MyISAM tables and aria-
If the terminal is stuck on the output of status
, you may have to press q
, for quit
, and everything should return back to normal.
You can also check the version by running:
$ mariadb -V
Output:
mariadb Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
MariaDB is now installed, but the configuration is not finished. Please refer to Secure MariaDB to finish the configuration.
Method 2 – Installing MariaDB from the MariaDB Repositories
To install MariaDB from the Official Mirror, follow these steps:
- Install
software-properties-common
so that we may use theadd-apt-repository
later on, to add the MariaDB Repository - Before adding the repository, add the MariaDB GPG key to our system:
$ sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
- Add the Official MariaDB Repository for Ubuntu 18.04 to our system:
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'
- Update your package index to ensure we’ll install the latest packages:
$ sudo apt update
- Now that the official repository is added and we’ve got our package list up-to-date, we can install MariaDB:
$ sudo apt install mariadb-server
- Check the status of the MariaDB service, to make sure the installation went well:
$ sudo systemctl status mariadb
- Check the MariaDB version by running:
$ mariadb -V
MariaDB’s configuration isn’t finished yet, however.
Securing MariaDB
To secure the installation, MariaDB comes with a script to help adjust some insecure defaults. Start the script by running:
$ sudo mysql_secure_installation
First, it will ask you if you’d like to enable VALIDATE PASSWORD PLUGIN
.
If you enable this, then depending on the type of validation you choose (
LOW
,MEDIUM
orSTRONG
), MySQL will return errors if your password does not meet the specified criteria for the policy you’ve chosen. This may conflict with other software packages, so it is up to you to decide. In our tutorial, we will chooseY
.
We’ll choose 1
. We recommend you choose what level of complexity you prefer between MEDIUM
and STRONG
.
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1
Please set the password for root here.
New password: Enter password Re-enter new password: Repeat password
You’ll also be prompted to answer some questions to remove/keep some defaults. We recommend you answer them as follows:
Remove anonymous users? [Y/n]: Y Disallow root login remotely? [Y/n]: Y Remove test database and access to it? [Y/n]: Y Reload privilege tables now? [Y/n]: Y
To make sure MySQL is properly installed, let’s test it out by running the following command, and entering the password you just created at the prompt:
$ sudo mysql -u root -p
To exit just run:
exit;
Connect to MariaDB
MariaDB should now be installed and configured. You can log into it using the command line to test that the install was successful.
To do this, we’ll run the following command, and enter the password we set for MariaDB at the prompt:
$ sudo mariadb -u root -p
After you’ve entered the password correctly, you should be greeted by the MariaDB shell.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.3.11-MariaDB-1:10.3.11+maria~bionic mariadb.org binary distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
That’s it. You can start using MariaDB.
Conclusion
Well done. You should now have MariaDB installed on your Ubuntu 18.04 machine. If you’ve encountered any issues, be sure to leave us a comment and we’ll get back to you as soon as possible.
Should you need to manage MariaDB via a web interface, you can follow our tutorial on installing phpMyAdmin on Ubuntu 18.04