MariaDB is an open source, fully compatible, relational database management system. It is commonly used as a replacement for MySQL due to its fault tolerance, speed, and scalability.
In this tutorial, you will learn how to install the latest version of MariaDB on Ubuntu 18.04.
- A command line/terminal window
- A user account with sudo privileges
- The apt package manager, included by default
Installing Latest MariaDB Version on Ubuntu 18.04 from Repositories
When installing MariaDB directly from its official repositories, you have the option to select a version for installation. The guide below focuses on the installation of MariaDB 10.4, the latest version available.
Note: Please visit the MariaDB Foundation downloads page to select the desired version. The instructions may differ slightly based on the chosen version to install.
Step 1: Add MariaDB Repositories
- Before attempting to install the software from independent sources like MariaDB, we will add packages that will help manage repositories more efficiently:
sudo apt-get install software-properties-common
- Import the MariaDB GPG key by using the following command:
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
- Add the MariaDB apt repository:
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el]http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu/ bionic main'
Step 2: Install MariaDB
- Update the packages list:
sudo apt update
- Install the MariaDB package:
sudo apt install mariadb-server mariadb-client -y
The MariaDB service starts automatically.
- Verify that the database is active and running, use the command:
sudo systemctl status mariadb
This is an example of the expected output:
- Check the MariaDB server version:
The terminal displays a detailed description of the version currently installed:
mysql Ver 15.1 Distrib 10.4.4-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Step 3: Secure MariaDB
To define security levels and access privileges, run the following command:
You now have the option to define the ‘root’ user password as well as create MariaDB user accounts.
Additionally, a series of questions will help you fine-tune your security settings. It is recommended to answer Yes (Y) to all of the questions. These short descriptions will help you to make an informed decision.
- Set root password? – Allows you to create a root database password.
- Remove anonymous users? – MariaDB has an anonymous user intended only for testing. Remove the default anonymous user before moving into a production environment. As it can quickly become a security liability.
- Disallow root login remotely? – Restrict ‘root’ user access to the local machine. This prevents the possibility of remote logins.
- Remove test database and access to it? – MariaDB has a default database intended for testing only. Remove it before moving to a production environment, as it is publicly accessible.
- Reload privilege tables now? – Reload the privilege tables to make sure that all the changes made take effect immediately
How to Connect to MariaDB from the Command Line
To connect to MariaDB from the command line, enter the command:
mysql -u root -p
Use the password defined earlier and the following screen will appear:
Now you will have access to the MariaDB monitor.
To gain control of the terminal again:
or alternatively use:
Note: If you need a database for storing complex data, that allows you to modify documents without affecting existing data structures. you may want to try installing MongoDB.
By following these steps, you have successfully installed the latest version of MariaDB on Ubuntu 18.04. We have also significantly improved database security levels by editing the default settings.
Most importantly, you have gained valuable insight and practice that will allow you to perform similar tasks more easily in the future.