Today most organizations prefer MariaDB as their database system over MySQL not only because of the open-source nature but also because MariaDB has now become more efficient in case of complex queries.

In this article, we will be discussing two different ways of installing MariaDB on Ubuntu. The first method will describe how to install MariaDB in Ubuntu from Ubuntu repositories, while the second method will describe how to install MariaDB from the official MariaDB repositories. 

You can also check our article on Install MongoDB on Ubuntu.

What is MariaDB?

MariaDB Logo - Installing MariaDB Ubuntu

MariaDB is a relational database management system. It was developed by the MariaDB foundation together with the original MySQL developers. It is considered a drop-in replacement for MySQL. MariaDB supports SQL, hence, you can use SQL queries to insert, manipulate, and retrieve data from MariaDB. MariaDB is mostly used as an alternative to MySQL. There are many similarities between the two database management systems (DBMSs). 

Pre-Requisites

  • Ubuntu 18.04 or above. 

Installing MariaDB on Ubuntu

Installing MariaDB from Ubuntu Repositories

To install MariaDB in Ubuntu from Ubuntu repositories, follow the steps given below:

Installing MariaDB on Ubuntu Step 1: Update the packages index. Simply run the following command from your Ubuntu terminal:

sudo apt update

After running the command, the packages will be up-to-date. 

Installing MariaDB on Ubuntu Step 2: Now that the package list has been updated, we should go ahead and install MariaDB. Just run the following command on the Ubuntu terminal: 

sudo apt install mariadb-server

You may be prompted to type the password for sudo user. 

Installing MariaDB on Ubuntu Step 3: The MariaDB service should be started automatically. However, you can verify its status by running the following command:

sudo systemctl status mariadb

It should be active and running. 

To know the version of MariaDB that has been installed, run the following command:

mysql -V

The output should be the version of MariaDB running on your computer. 

This will be a confirmation that you’ve successfully installed MariaDB on your Ubuntu system. 

Installing MariaDB from MariaDB Repositories

The official MariaDB repositories normally host the latest versions of MariaDB. Before starting the installation, it will be good for you to visit the official MariaDB repository page and check the latest version of MariaDB. 

The installation can be done by following the steps given below:

Installing MariaDB on Ubuntu Step 1: Run the following command to add the MariaDB GPG key to the system:

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

Installing MariaDB on Ubuntu Step 2: Once the key has been imported, run the following command to add the MariaDB repository:

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.accretive-networks.net/mariadb/repo/10.3/ubuntu bionic main'

In case you get an error message that says, “add-apt-repository command not found”, just install the “software-properties-common” package. 

Installing MariaDB on Ubuntu Step 3: Before installing any package from the MariaDB repository, you should first update the package list. This requires you to run the following command:

sudo apt update

Installing MariaDB on Ubuntu Step 4: After the repository has been added, run the following command to install the MariaDB package:

sudo apt install mariadb-server

Installing MariaDB on Ubuntu Step 5: The MariaDB service should be started automatically. To verify its status, run the following command:

sudo systemctl status mariadb

It should be active and running. 

Installing MariaDB on Ubuntu Step 6: You can check the version of MariaDB installed on your computer by running the following command:

mysql -V

Configuring MariaDB Security

To secure the MariaDB installation, we should run the security script that comes with MariaDB. The script should secure the less secure settings that come with MariaDB. For example, sample users and remote root logins. 

To execute the security script, run the following command from Ubuntu terminal:

sudo mysql_secure_installation

You will be taken through a series of instructions to help you improve the security of your MariaDB installation. This will include setting up the password for the root user, removing the anonymous user, removing the test database, and restricting root user access to the local host. 

The script will reload the privilege tables so that changes may take effect immediately. The steps will be explained in detail and you should answer by typing “Y” for “Yes”. 

Connecting to MariaDB

It is possible for you to establish a connection to the MariaDB server from your Ubuntu terminal using the MariaDB client. To log into MariaDB as the root user, run the following command:

mysql -u root -p

You will be prompted to enter the root password that you set when running the security script. If the authentication process runs successfully, you will be presented with the MariaDB terminal. 

You can now run SQL commands against your MariaDB Server. The SQL commands will help you perform tasks like creating databases, creating tables, inserting data into the tables, updating, and retrieving data from tables. 

For example, let’s create a database and give it the name sampledb. Run the following command on the MariaDB terminal:

create database sampledb;

To work on the database, you must select it. Run the following command:

use sampledb

Let us create a table within the database. The table will be given the name testtb:

CREATE TABLE testtb (name VARCHAR(20), age INTEGER)

The command should successfully create a table in the database. 

Limitations of Installing MariaDB on Ubuntu

Although it is possible to install MariaDB on Ubuntu, you may encounter a number of challenges including the following:

  1. Technical know-how is needed. The process of installing and configuring MariaDB on Ubuntu is very technical. This means that technical expertise is needed for this. 
  2. The process is prone to errors. This comes as a result of conflicts in versions of different packages installed in the Ubuntu system. 

Conclusion

In this article, you learned the steps for Installing MariaDB on Ubuntu, the method to configure and connect it along the limitations of the deployment. If you are interested in setting up MariaDB on a Raspberry Pi you can find the guide here.

Integrating and analyzing data from a huge set of diverse sources can be challenging, this is where Hevo comes into the picture. Hevo Data, a No-code Data Pipeline helps you transfer data from a source of your choice in a fully automated and secure manner without having to write the code repeatedly. Hevo with its strong integration with 150+ sources & BI tools, allows you to not only export & load Data but also transform & enrich your Data & make it analysis-ready in a jiffy.

Visit our Website to Explore Hevo

Want to take Hevo for a spin? Sign Up for a 14-day free trial and experience the feature-rich Hevo suite first hand.

Share your experience of installing MariaDB on Ubuntu in the comments section below!

Nicholas Samuel
Technical Content Writer, Hevo Data

Nicholas Samuel is a technical writing specialist with a passion for data, having more than 14+ years of experience in the field. With his skills in data analysis, data visualization, and business intelligence, he has delivered over 200 blogs. In his early years as a systems software developer at Airtel Kenya, he developed applications, using Java, Android platform, and web applications with PHP. He also performed Oracle database backups, recovery operations, and performance tuning. Nicholas was also involved in projects that demanded in-depth knowledge of Unix system administration, specifically with HP-UX servers. Through his writing, he intends to share the hands-on experience he gained to make the lives of data practitioners better.