Pentarock Technologies

SHARING KNOWLEDGE

How to Install MariaDB 10 on Ubuntu 20.04

How To Install MariaDB 10 on Ubunti 20.04 Focal Fossa

Here we are going to learn how to Install MariaDB 10 on Ubuntu 20.04 LTS. MariaDB Database Server formerly known as MySQL Database Server  is currently among the most popular free and open source relational database. MariaDB Server is developed by the same team of developers who developed MySQL. In addition to above the MariaDB Server is guaranteed to always stay open source in the future. Also, MariaDB Database Server is part of the default packaging of most of the Debian and Ubuntu based Linux distributions. MariaDB Database Server is a relational database management system. It is around us for the last 20 years. It is one of the most widely used.

However, MariaDB Database Server is the most suitable alternative to MySQL. It is also a part of the most popular LAMP Server comprising Linux Operating System, Apache webserver, MariaDB Database Server and the programming language as PHP, Python or Perl.

Certainly, here in this guide we will learn, how to install MariaDB 10.3 on Ubuntu 20.04 LTS Server or Desktop operating system.

As we already know that the MariaDB Database Server and Client system is a part of the packaging of most of the Debian and Ubuntu based Linux distributions, this installation procedure will be same for the other similar distributions.

Prerequisites for Installation of MariaDB 10.3 on Ubuntu 20.04

  • To best use this tutorial, we will need a Ubuntu 20.04 Server or Desktop system.
  • Further, this Ubuntu System must have a root user and UFW firewall configured.
  • Also, we can setup this by using our Ubuntu 20.04 Focal Fossa installation tutorial:
    How to Install Ubuntu 20.04 LTS Focal Fossa

Installation Procedure of MariaDB 10 on Ubuntu 20.04 LTS Focal Fossa 

However, here, we will describe the installation procedure in steps.

The first step is to update the operating system’s package index using the apt update command.

sudo apt-get update

Further, in the following step we will install the MariaDB Server and MariaDB Client packages using the same apt-get command of Ubuntu Operating System. Also, this command will also pull the other dependency packages along with the database server and client packages. The following command will install the MariaDB Server and Client without any prompt and will set a blank password for the root user. It will also install and configure a test database along with system database.  This will leave the default MariaDB database insecure.

sudo apt-get install mariadb-server mariadb-client

Configure and Secure MariaDB Database Server

After the installation of MariaDB Server and Client is complete, we will run mysql_secure_installation script. Moreover, this script will be used to set the database root user password, remove test database, remove anonymous users and flush privileges. By using this script we will be able to restrict the access to the database and we will be able to secure our database server installation.

sudo mysql_secure_installation

Now, the above script will prompt us a series of questions. Through our responses to these questions we will be able to change and make secure our MariaDB database server default installation.

The first prompt will be to enter the existing password of the MariaDB root User. If this is a fresh installation of the MariaDB Database Server, the the root user’s password will be blank. Therefore we have to just press the enter key in response to the current password query. Below given are the full text of prompts pf mysql_secure_installation script and the responses to be given.

Enter current password for root (enter for none): [Press Enter Key]
Set root password? [Y/n] Y            [Press Y here to set the new password]
New password:                         [Enter New root User Password here]
Re-Enter New Password :               [Repeat the above password here]
Remove the anonymous users ? (Y/n)    [Press  Y  to  remove anonymous users]
Disallow root login remotely? (Y/n)   [Press Y to disallow root login remotely]
Reload privilege tables now? (Y/n)    [Press Y to reload the privilege tables]

With the completion of the above command we have completed the installation and initial security configuration of MariaDB Server on Ubuntu 20.04 LTS.

Change the Password Authentication Method in MariaDB

However, by default MariaDB use the UNIX socket plugin to authenticate users.

Now, we will set the password authentication method in MariaDB Server to native. Later when we will install PHPMyAdmin, this will enable us to connect as root user. To do this, login to MariaDB Server as root user and issue following commands terminal window step by step in the given order.

sudo mysql -u root –p                [Run the Command]
Enter password:                      [Enter root User Password]

The output of the above command will be similar to shown below and we will get the MariaDB command prompt.

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 61
Server version: 10.3.29-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
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)]>                [MariaDB Database Server Command Prompt]

Run the given below SQL statement on the MariaDB Command Prompt. MariaDB [(none)]> update mysql.user set plugin = ‘mysql_native_password’ where User = ‘root’; Query OK, 0 rows affected (0.000 sec) Rows matched: 1  Changed: 0  Warnings: 0 MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.000 sec) MariaDB [(none)]> quit

Now, quit the MariaDB Database Server Command prompt by issuing the “quit” command. Now the installation part is complete.

Furthermore, this is the time for testing the newly installed MariaDB Database Server.

Furthermore, to test the MariaDB installation. Run the following command in the terminal window.

sudo systemctl status mariadb

The output of the command will be similar to given below.

. mariadb.service – MariaDB 10.3.29 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2021-07-22 12:38:32 IST; 25min ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 53176 (mysqld)
Status: “Taking your SQL requests now…”
Tasks: 31 (limit: 4657)
Memory: 66.3M
CGroup: /system.slice/mariadb.service
└─53176 /usr/sbin/mysqld
. . .

How to Start, Stop and Restart MariaDB Database Server

To start, stop and restart MariaDB Database Server run the following command in the terminal as root.

sudo systemctl start mariadb
sudo systemctl stop mariadb
sudo systemctl restart mariadb

That’s it, Now, we have successfully installed and configured the MariaDB Database Server and Client on Ubuntu 20.04 LTS Focal Fossa. Now we can start using it.

Leave a Reply

Your email address will not be published. Required fields are marked *