How to Install and Start Using MariaDB on Ubuntu 20.04 (Step-By-Step Guide)

 

MariaDB is an open-source, freely accessible database management software that serves as a viable alternative to Oracle's MySQL database server. It's a community-supported, multi-user, and multi-threaded database server. 

It originated from the efforts of the original Oracle MySQL database server community developers. Moreover, you can install the MariaDB server on a wide range of operating systems, including various Linux distributions.

When compared to MySQL, MariaDB offers superior performance, speed, and security. Additionally, it surpasses MySQL in terms of replication, thanks to its efficient asynchronous Master-slave (MariaDB Client and MariaDB Server) replication system.

This article will demonstrate the step-by-step guidelines on how to install MariaDB on Ubuntu 22.04 in two different ways. In addition, after installing MariaDB, we will learn how to start using it on the Ubuntu 22.04 system. 

Methods to Install MariaDB on Ubuntu 22.04

You can install the MariaDB server on Ubuntu using two different methods that we will discuss in this section. 

  1. Install MariaDB on Ubuntu using Ubuntu APT repositories.
  2. Install MariaDB using the Official MariaDB repository.

Method 1: Installing MariaDB on Ubuntu 22.04 Using Ubuntu APT Repositories

This method is the quickest and easiest way to install MariaDB on Ubuntu 22.04. However, this method will not install the latest MariaDB version on your Ubuntu system. To install MariaDB from Ubuntu APT repositories, follow the below-given steps:

Step 1: Update Ubuntu APT Repositories

It is recommended that you first update all Ubuntu APT repositories before installing any new packages on your system. You can update the system APT repositories using this command:

$ sudo apt update

Step 2: Install MariaDB on Ubuntu

You can install MariaDB on Ubuntu 22.04 from the default Ubuntu APT repositories. To do this, type the following command on the terminal:

$ sudo apt install mariadb-server mariadb-client

After executing the above command, a confirmation prompt will display on the terminal window. Press “y” and hit “Enter” to download and install all required MariaDB packages on your Ubuntu system. In a while, you will notice the installation is completed on your system, and you will see the following output:

Step 3: Verify the MariaDB Installation

You can verify the MariaDB installation on your system by displaying the MariaDB version using the following command:

$ sudo mysqladmin version

After running the above command, you will see the installed MariaDB version on the terminal window as follows:

Method 2: Installing MariaDB on Ubuntu 22.04 Using the Official MariaDB Repositories

As we mentioned above, installing MariaDB using Ubuntu APT repositories doesn’t provide you with the latest MariaDB version. However, you can install the latest MariaDB version from the official MariaDB repositories. 

This method is the recommended way to install MariaDB on the Ubuntu system. In this instance, you need to use the official MariaDB repository to install the latest MariaDB version. To install MariaDB using the official MariaDB repository, follow the steps below:

Step 1: Install Prerequisites or Dependencies

First, install all required packages and dependencies that are necessary to run MariaDB on Ubuntu 22.04:

$ sudo apt install -y software-properties-common

Step 2: Import the GPG Key

In this step, you will import the GPG key using the following command:

$ sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

Step 3: Add the MariaDB APT Repository

After successfully importing the GPG signing key, you will include the MariaDB APT repository in your Ubuntu system. You can enable the repository specifically for MariaDB version 10.11, but you can replace this version based on your requirements with the one you wish to install. At the time of writing this article, the stable MariaDB version is 10.11.

$ sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.11/ubuntu focal main'

Step 4: Update the Local APT Repositories

To complete the process, ensure that you refresh your local repositories. After that, install the MariaDB server and MariaDB client by using the APT package manager:

$ sudo apt update 

$ sudo apt install mariadb-server mariadb-client

The above command will install the MariaDB 10.11 version, including all additional required dependencies and packages on Ubuntu 22.04.

Step 5: Check MariaDB Version

After installing MariaDB on Ubuntu, verify its installation. Check the installed MariaDB version using the following command:

$ mariadb --version 

Step 6: Enable and Start the MariaDB Service

The MariaDB database will automatically start running on your system upon successful installation. You can check the MariaDB running status using the following command:

$ sudo systemctl status mariadb

As you can see, the MariaDB server is active and running on this system. If this is not enabled and running by default on your system, you can enable and start the MariaDB service using the following commands:

$ sudo systemctl start mariadb

$ sudo systemctl enable mariadb

The command mentioned above guarantees that MariaDB will initiate automatically whenever you restart or reboot your system.

Step 7: Start and Use MariaDB

Now, you can start using the MariaDB database on your system. To start the MariaDB database, use the following command:

$ sudo mariadb

As you can see, the MariaDB shell launched on the terminal where you can run database commands. 

Configure Secure MariaDB Installation 

It's recommended that you execute the security script provided by MariaDB to improve the security of your MariaDB installation. This script is designed to secure the MariaDB installation by addressing less secure configuration issues that may exist, such as eliminating sample users and preventing remote root logins. To make your MariaDB configuration secure, run the following security script:

$ sudo mysql_secure_installation

After executing the above command, you will need to answer a series of user confirmation prompts that will change the security options for the MariaDB database secure configuration:

  1. In the first user prompt, you will provide the current root account password. If none is set up yet, just press “Enter” from your keyboard.
  2. Set up a root password for your MariaDB database. It ensures that no one can access or log in as a root user inside your database without password authentication. So, here, you will press the “y” key. Enter the password for your database and then confirm it. Here, we have already set a secure root password. However, you will change it based on your requirements.

After that, you will need to press “y” to configure the secure MariaDB installation for the following options:

  • Removes anonymous users from the database server: “Y.”
  • Disables remote root login: “Y.” This option ensures that only the root user can access and log in to the MariaDB database server using “localhost.”
  • Remove the test database that comes with MariaDB by default: “Y.”
  • Reload privilege tables now. “Y” ensures that all changes take effect immediately. 

Congratulations! We have successfully configured the secure installation plugin for the MariaDB database. If you are using a VPS server, you can follow the same steps to configure this plugin on your Linux server.

Create an Administrative User for Password Authentication

To create an administrative user, you will create a new user account using the MariaDB database and assign privileges to that user. First, log in as root user to access the MariaDB database:

$ sudo mariadb -u root -p 

Now, create a user with your desired name and assign a password to this user using the following command:

> CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'secure_password' WITH GRANT OPTION;

In the command above, replace “user_name” and “secure_password” with your credentials.

You can also grant privileges separately using the following command:

GRANT ALL PRIVILEGES ON *.* TO 'user_name'@'localhost';

The use of the "." wildcard notation signifies that the user is granted permission to perform any operation on any database within the database server.

To commit changes or apply all changes, run the following command:

> FLUSH PRIVILEGES;

To exit from the MariaDB database, use this command:

>exit

Test MariaDB Configuration for Administrative User

Once you configured your MariaDB database on Ubuntu, you can now log in to your database and execute queries. To log in to the database, you need to use the above administrative user credentials. To do this, execute the following command:

$ sudo mariadb -u samreena -p

After running this command, enter your database administrative user password and hit “Enter.” The following screen will display on your terminal:

List All DataBases

Here, you can run different database queries. For example, let’s say you want to list all MariaDB databases. To show all databases, use the following command:

> show databases

Create a New Database

To create a new database, execute the following database query:

> create database new_testdb

List Users

To list all localhost users for your database, run this query:

> select host, user from mysql.user;

Conclusion

In this tutorial, we learned how to install MariaDB on the Ubuntu 22.04 system using two different methods. First, how to install MariaDB using the Ubuntu APT repository and second, how to install MariaDB from the official MariaDB repositories. 

In addition, we have also figured out how to configure the secure MariaDB installation and execute queries on it. If you want to learn more about MariaDB database commands and repositories, you can visit the official MariaDB documentation.





Items from an article
  • KVM VPS 4 GB
    • Country: Netherlands
    • City: Amsterdam
    • CPU 2 x Xeon Core
    • RAM 4 GB
    • HDD 50GB
    • BANDWIDTH 1 Gbps
    • IPv4 / IPv6
    € 14/month
    14/month
  • KVM VPS 8 GB
    • Country: United States
    • City: New Jersey
    • CPU 4 x Xeon Core
    • RAM 8 GB
    • HDD 80GB
    • BANDWIDTH 1 Gbps
    • IPv4 / IPv6
    € 30/month
    30/month
  • KVM VPS 12 GB
    • Country: United States
    • City: New Jersey
    • CPU 6 x Xeon Core
    • RAM 12 GB
    • HDD 140GB
    • BANDWIDTH 1 Gbps
    • IPv4 / IPv6
    € 60/month
    60/month
  • KVM VPS 16 GB
    • Country: United States
    • City: New Jersey
    • CPU 8 x Xeon Core
    • RAM 16 GB
    • HDD 200GB
    • BANDWIDTH 1 Gbps
    • IPv4 / IPv6
    € 88/month
    88/month
Blog company: