How to Install MariaDB on Ubuntu 18.04|20.04|22.04

How to Install MariaDB on Ubuntu 18.04|20.04|22.04

MariaDB is a popular community-developed, commercially supported system of the MySQL relational database management system made with the purpose to remain free and open-source software under the GNU General Public Licence. It has more features with new storage engines and better performance.

Features of MariaDB

MariaDB comes with a number of features;

   –sys schema supported that contains views and procedures for investigating performance problems.

   –Oracle compatibility

Ignored indexes that are visible and maintained but not used by the optimizer.

   -SKIP LOCKED.

Step by Step Installation of MariaDB on Ubuntu 20.04

Installation of MariaDB requires you to add the MariaDB repository to the system. Afterward, the installation will be done from the APT repository added without any problems encountered.

Step 1: Update System

As usual, ensure your system is updated then install the software-properties-common package.

$ sudo apt upgrade && sudo apt upgrade -y
$ sudo apt -y install software-properties-common

Step 2: Install MariaDB Server on 18.04|20.4|22.04

The following command can be used to install MariaDB in Ubuntu 18.04, 20.04, and 22.04 as well.

 $ sudo apt install mariadb-server mariadb-client

From below output type Y to accept the installation.

The following additional packages will be installed:
galera-3 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client-10.3 mariadb-client-core-10.3
mariadb-common mariadb-server-10.3 mariadb-server-core-10.3 mysql-common socat
Suggested packages:
libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx mariadb-test tinyca
The following NEW packages will be installed:
galera-3 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl liblwp-mediatypes-perl libmysqlclient21 libsnappy1v5 libterm-readkey-perl libtimedate-perl liburi-perl mariadb-client mariadb-client-10.3
mariadb-client-core-10.3 mariadb-common mariadb-server mariadb-server-10.3 mariadb-server-core-10.3 mysql-common socat
0 upgraded, 29 newly installed, 0 to remove and 13 not upgraded.
Need to get 21.3 MB of archives.
After this operation, 174 MB of additional disk space will be used.
Do you want to continue? [Y/n]Y

By default, MariaDB will start automatically upon installation. Use the below command to confirm the status.

$ sudo systemctl status mariadb

 mariadb.service - MariaDB 10.3.34 database server
Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-07-05 14:59:05 UTC; 19s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Main PID: 9240 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 31 (limit: 2232)
Memory: 64.6M
CGroup: /system.slice/mariadb.service
└─9240 /usr/sbin/mysqld

Step 3: Secure MariaDB server on 18.04|20.04|22.04

At this point, you have to manually run the MySQL hardening command. This is to ensure that your database is secure.

 $ sudo mysql_secure_installation

On the prompt below to enter the password, just click ENTER Key to continue.

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): <ENTER>
OK, successfully used password, moving on...

On the next step, select Y to accept the setup of a new password for root.

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n]Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

$ Remove anonymous users? [Y/n] Y
... Success!

Normally, the root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess the root password from the network.

$ Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing and should be removed
before moving into a production environment.

$ Remove test database and access to it? [Y/n] Y
 - Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

$ Reload privilege tables now? [Y/n] Y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!

Test login to MariaDB shell using the mysql command:

$ mysql 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 46
Server version: 10.3.34-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)]> 

You will notice that still you can login without being prompted to enter the password. Use the below command to reset the root password. Replace “mariaDB_Secure_Password” with your preferred password.

$ ALTER USER "root"@"localhost" IDENTIFIED BY "mariaDB_Secure_Password";
Query OK, 0 rows affected (0.000 sec)
MariaDB [(none)]>

Now on login you have to enter the password.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 49
Server version: 10.3.34-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)]> 

Check the version using the following command:

$ SELECT VERSION();
+----------------------------------+
| VERSION()                        |
+----------------------------------+
| 10.3.34-MariaDB-0ubuntu0.20.04.1 |
+----------------------------------+
1 row in set (0.000 sec)

You have successfully installed MariaDB in Ubuntu 18.04|20.04|22.04.

How To Install MySQL in Ubuntu 18.04

How to Install MySQL CLient on Ubuntu 20.04 LTS.

How to Configure Virtual Hosts in Apache

2 thoughts on “How to Install MariaDB on Ubuntu 18.04|20.04|22.04

Leave a Reply

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

six + 2 =