How to Install MariaDB on Ubuntu 18.04

MariaDB is an open source, multi-threaded relational database management system.MariaDB is a fork of the very popular MySQL database management system, and it is now considered as a full drop-in replacement for MySQL.

In this tutorial we will show you two different methods on how to install MariaDB on your Ubuntu 18.04.

  1. Install MariaDB from the Ubuntu repositories
  2. Install MariaDB from the official MariaDB repositories

Ubuntu 18.04 includes MariaDB which the latest version for Ubuntu 18.04 in its main repository.So it is recommended to use the first method and install MariaDB packages provided by Ubuntu.

In this tutorial, we take the MariaDB 10.1 installation as an example.

Prerequisites

Before, you must have an account with sudo privileges and make sure your Ubuntu 18.04 server can access the Internet.

Install MariaDB on Ubuntu from The Ubuntu Repository

MariaDB version 10.1 is included in the Ubuntu main repositories.Before starting the installation,you’d better update the apt package manager index.

Update the apt package index.

sudo apt update

Install the MariaDB package by typing the following command:

sudo apt install mariadb-server

If you want to install client package by typing the following command:

 sudo apt install mariadb-client

Use mysql_secure_installation to secure the installation of MariaDB server.

Typing the following command:

sudo mysql_secure_installation

After completing installation MariaDB will start automatically. Check MySQL version by typing:

mysql -V

For more details about mysql status, you can typing the following command:

sudo systemctl status mariadb

The output should below:

 mariadb.service - MariaDB database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset
Active: active (running) since Mon 2019-05-13 1931 UTC; 38s ago
Main PID: 13932 (mysqld)
Status: "Taking your SQL requests now..."
    Tasks: 27 (limit: 507)
CGroup: /system.slice/mariadb.service
        └─13932 /usr/sbin/mysqld

Install MariaDB 10 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.

Before continuing with the next step you should visit the MariaDB downloads page and check if there is a new version available.

To install MariaDB 10 on your Ubuntu 18.04 server perform the following steps:

First, add the MariaDB GPG key to your system using the following command:

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

Second,when the key is imported, add the MariaDB repository with:

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://ftp.utexas.edu/mariadb/repo/10.3/ubuntu bionic main'

Third,To be able to install packages from the MariaDB repository you’ll need to update the packages list:

sudo apt update

Now,you can install mariadb by typing following command:

sudo apt install mariadb-server

The MariaDB service will start automatically, to verify it type:

sudo systemctl status mariadb

The ouput should below:

● mariadb.service - MariaDB 10.3.8 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/mariadb.service.d
        └─migrated-from-my.cnf-settings.conf
Active: active (running) since Mon 2019-05-13 1930 UTC; 56s ago
    Docs: man:mysqld(8)
        https://mariadb.com/kb/en/library/systemd/
Main PID: 16417 (mysqld)
Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 507)
CGroup: /system.slice/mariadb.service
        └─16417 /usr/sbin/mysqld

Print the MariaDB server version, typing:

mysql -V

Securing MariaDB server

Run the mysql_secure_installation command to improve the security of the MariaDB installation:

sudo mysql_secure_installation

The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine and remove the test database. At the end the script will reload the privilege tables ensuring that all changes take effect immediately.

All steps are explained in detail and it is recommended to answer “Y” (yes) to all questions.

Connect to the MariaDB server

To connect to the MariaDB server through the terminal we can use the MariaDB client.

To log in to the MariaDB server as the root user type:

mysql -u root -p

or

sudo mysql -u root -p

You will be prompted to enter the root password you have previously set when the mysql_secure_installation script was run.

Once you enter the password you will be presented with the MariaDB shell as shown below:

The output should below:

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Conclusion

That’s It! In this article, we have explained how to install MariaDB in Ubuntu 18.04. If you have any questions or thoughts to share, don’t forget to leave a comment to reach us.

Leave a Reply