How to Install MariaDB Database Server in Linux CentOS

Posted on

Introduction

The installation process of MariaDB Database Server is the main content of this article. The target of the installation is a machine with a CentOS operating system run in it. The process for installing MariaDB Database is using a command line interface. There are several parts to install the MariaDB database server. The first one is the installation part. The next one is the security configuration part. After that, another part is the firewall configuration. So, all of the parts of processes exist as follows :

MariaDB Database Server Installation

This part will only explain about how to install MariaDB Database Server in the command line interface using ‘yum’ tool. Just follow all the steps below :

[root@hostname ~]$ yum search mariadb
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror.*************
* extras: mirror.*************
* updates: mirror.*************
=========================================================================== N/S matched: mariadb ===========================================================================
mariadb-bench.x86_64 : MariaDB benchmark scripts and data
mariadb-devel.i686 : Files for development of MariaDB/MySQL applications
mariadb-devel.x86_64 : Files for development of MariaDB/MySQL applications
mariadb-embedded.i686 : MariaDB as an embeddable library
mariadb-embedded.x86_64 : MariaDB as an embeddable library
mariadb-embedded-devel.i686 : Development files for MariaDB as an embeddable library
mariadb-embedded-devel.x86_64 : Development files for MariaDB as an embeddable library
mariadb-libs.i686 : The shared libraries required for MariaDB/MySQL clients
mariadb-libs.x86_64 : The shared libraries required for MariaDB/MySQL clients
mariadb-server.x86_64 : The MariaDB server and related files
mariadb.x86_64 : A community developed branch of MySQL
mariadb-test.x86_64 : The test suite distributed with MariaD
Name and summary matches only, use "search all" for everything.
[centos@hostname ~]$

From the output of the command execution above, there is an installation package with the name of mariadb-server.x86_64.

After finding the correct installation package, just run the installation process by executing the following command :

[root@hostname ~]# yum -y install mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.*************
* extras: mirror.*************
* updates: mirror.*************
Resolving Dependencies
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.65-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.65-1.el7 for package: 1:mariadb-server-5.5.65-1.el7.x86_64
--> Processing Dependency: mariadb(x86-64) = 1:5.5.65-1.el7 for package: 1:mariadb-server-5.5.65-1.el7.x86_64
...
...
...
Dependencies Resolved
======================================================================================================================== 
Package                                Arch                  Version                         Repository           Size
========================================================================================================================
Installing:
mariadb-server                         x86_64                1:5.5.65-1.el7                  base                 11 M
Installing for dependencies:
libaio                                 x86_64                0.3.109-13.el7                  base                 24 k
mariadb                                x86_64                1:5.5.65-1.el7                  base                8.7 M
...
...
...
Transaction Summary
========================================================================================================================
Install  1 Package  (+37 Dependent packages)
Upgrade             (  1 Dependent package)
Total download size: 33 M
Downloading packages:
...
...
...
Trying other mirror.
(1/39): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm                                                                                                |  57 kB  00:00:00
(2/39): perl-Carp-1.26-244.el7.noarch.rpm                                                                                                            |  19 kB  00:00:00
(3/39): perl-DBD-MySQL-4.023-6.el7.x86_64.rpm                                                                                                        | 140 kB  00:00:00
(4/39): perl-Data-Dumper-2.145-3.el7.x86_64.rpm                                                                                                      |  47 kB  00:00:00
(5/39): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm                                                                                               |  32 kB  00:00:02
(6/39): perl-Exporter-5.68-3.el7.noarch.rpm                                                                                                          |  28 kB  00:00:00
(7/39): perl-File-Path-2.09-2.el7.noarch.rpm                                                                                                         |  26 kB  00:00:00
(8/39): perl-Encode-2.51-7.el7.x86_64.rpm                                                                                                            | 1.5 MB  00:00:02
(9/39): perl-Filter-1.49-3.el7.x86_64.rpm                                                                                                            |  76 kB  00:00:00
(10/39): perl-Getopt-Long-2.40-3.el7.noarch.rpm                                                                                                      |  56 kB  00:00:00
(11/39): perl-5.16.3-295.el7.x86_64.rpm                                                                                                              | 8.0 MB  00:00:04
(12/39): perl-HTTP-Tiny-0.033-3.el7.noarch.rpm                                                                                                       |  38 kB  00:00:00
(13/39): perl-File-Temp-0.23.01-3.el7.noarch.rpm                                                                                                     |  56 kB  00:00:02
(14/39): perl-IO-Compress-2.061-2.el7.noarch.rpm                                                                                                     | 260 kB  00:00:00
(15/39): perl-Net-Daemon-0.48-5.el7.noarch.rpm                                                                                                       |  51 kB  00:00:00
(16/39): perl-PathTools-3.40-5.el7.x86_64.rpm                                                                                                        |  82 kB  00:00:00
(17/39): perl-PlRPC-0.2020-14.el7.noarch.rpm                                                                                                         |  36 kB  00:00:00
(18/39): perl-DBI-1.627-4.el7.x86_64.rpm                                                                                                             | 802 kB  00:00:04
(19/39): perl-Pod-Escapes-1.04-295.el7.noarch.rpm                                                                                                    |  51 kB  00:00:00
(20/39): perl-Pod-Perldoc-3.20-4.el7.noarch.rpm                                                                                                      |  87 kB  00:00:00
(21/39): perl-Pod-Simple-3.28-4.el7.noarch.rpm                                                                                                       | 216 kB  00:00:00
(22/39): perl-Pod-Usage-1.63-3.el7.noarch.rpm                                                                                                        |  27 kB  00:00:00
(23/39): perl-Scalar-List-Utils-1.27-248.el7.x86_64.rpm                                                                                              |  36 kB  00:00:00
(24/39): perl-Socket-2.010-5.el7.x86_64.rpm                                                                                                          |  49 kB  00:00:00
(25/39): perl-Storable-2.45-3.el7.x86_64.rpm                                                                                                         |  77 kB  00:00:00
(26/39): perl-Text-ParseWords-3.29-4.el7.noarch.rpm                                                                                                  |  14 kB  00:00:00
(27/39): perl-Time-HiRes-1.9725-3.el7.x86_64.rpm                                                                                                     |  45 kB  00:00:00
(28/39): perl-Time-Local-1.2300-2.el7.noarch.rpm                                                                                                     |  24 kB  00:00:00
(29/39): mariadb-server-5.5.65-1.el7.x86_64.rpm                                                                                                      |  11 MB  00:00:06
(30/39): perl-constant-1.27-2.el7.noarch.rpm                                                                                                         |  19 kB  00:00:00
(31/39): perl-macros-5.16.3-295.el7.x86_64.rpm                                                                                                       |  44 kB  00:00:00
(32/39): perl-libs-5.16.3-295.el7.x86_64.rpm                                                                                                         | 689 kB  00:00:00
(33/39): perl-parent-0.225-244.el7.noarch.rpm                                                                                                        |  12 kB  00:00:00
(34/39): perl-threads-1.87-4.el7.x86_64.rpm                                                                                                          |  49 kB  00:00:00
(35/39): perl-podlators-2.5.1-3.el7.noarch.rpm                                                                                                       | 112 kB  00:00:00
(36/39): perl-threads-shared-1.43-6.el7.x86_64.rpm                                                                                                   |  39 kB  00:00:00
(37/39): libaio-0.3.109-13.el7.x86_64.rpm                                                                                                            |  24 kB  00:00:00
(38/39): mariadb-libs-5.5.65-1.el7.x86_64.rpm                                                                                                        | 759 kB  00:00:00
(39/39): mariadb-5.5.65-1.el7.x86_64.rpm                                                                                                             | 8.7 MB  00:00:02
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                       1.1 MB/s |  33 MB  00:00:30
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating   : 1:mariadb-libs-5.5.65-1.el7.x86_64                                                                                                                      1/40
Installing : 1:perl-parent-0.225-244.el7.noarch                                                                                                                      2/40
Installing : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                                                       3/40
Installing : perl-podlators-2.5.1-3.el7.noarch                                                                                                                       4/40
Installing : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                                                      5/40
Installing : 1:perl-Pod-Escapes-1.04-295.el7.noarch                                                                                                                  6/40
Installing : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                                                  7/40
Installing : perl-Encode-2.51-7.el7.x86_64                                                                                                                           8/40
Installing : perl-Pod-Usage-1.63-3.el7.noarch                                                                                                                        9/40
Installing : 4:perl-libs-5.16.3-295.el7.x86_64                                                                                                                      10/40
Installing : 4:perl-macros-5.16.3-295.el7.x86_64                                                                                                                    11/40
Installing : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                                                  12/40
Installing : perl-Exporter-5.68-3.el7.noarch                                                                                                                        13/40
Installing : perl-constant-1.27-2.el7.noarch                                                                                                                        14/40
Installing : perl-Socket-2.010-5.el7.x86_64                                                                                                                         15/40
Installing : perl-Time-Local-1.2300-2.el7.noarch                                                                                                                    16/40
Installing : perl-Carp-1.26-244.el7.noarch                                                                                                                          17/40
Installing : perl-Storable-2.45-3.el7.x86_64                                                                                                                        18/40
Installing : perl-PathTools-3.40-5.el7.x86_64                                                                                                                       19/40
Installing : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                                             20/40
Installing : perl-File-Temp-0.23.01-3.el7.noarch                                                                                                                    21/40
Installing : perl-File-Path-2.09-2.el7.noarch                                                                                                                       22/40
Installing : perl-threads-shared-1.43-6.el7.x86_64                                                                                                                  23/40
Installing : perl-threads-1.87-4.el7.x86_64                                                                                                                         24/40
Installing : perl-Filter-1.49-3.el7.x86_64                                                                                                                          25/40
Installing : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                                                    26/40
Installing : perl-Getopt-Long-2.40-3.el7.noarch                                                                                                                     27/40
Installing : 4:perl-5.16.3-295.el7.x86_64                                                                                                                           28/40
Installing : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                    29/40
Installing : 1:mariadb-5.5.65-1.el7.x86_64                                                                                                                          30/40
Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                                             31/40
Installing : perl-Net-Daemon-0.48-5.el7.noarch                                                                                                                      32/40
Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                                                            33/40
Installing : perl-IO-Compress-2.061-2.el7.noarch                                                                                                                    34/40
Installing : perl-PlRPC-0.2020-14.el7.noarch                                                                                                                        35/40
Installing : perl-DBI-1.627-4.el7.x86_64                                                                                                                            36/40
Installing : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                                                      37/40
Installing : libaio-0.3.109-13.el7.x86_64                                                                                                                           38/40
Installing : 1:mariadb-server-5.5.65-1.el7.x86_64                                                                                                                   39/40
Cleanup    : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                                   40/40
Verifying  : perl-HTTP-Tiny-0.033-3.el7.noarch                                                                                                                       1/40
Verifying  : 1:mariadb-server-5.5.65-1.el7.x86_64                                                                                                                    2/40
Verifying  : perl-IO-Compress-2.061-2.el7.noarch                                                                                                                     3/40
Verifying  : perl-threads-shared-1.43-6.el7.x86_64                                                                                                                   4/40
Verifying  : 4:perl-Time-HiRes-1.9725-3.el7.x86_64                                                                                                                   5/40
Verifying  : 1:perl-Pod-Escapes-1.04-295.el7.noarch                                                                                                                  6/40
Verifying  : perl-DBD-MySQL-4.023-6.el7.x86_64                                                                                                                       7/40
Verifying  : perl-Exporter-5.68-3.el7.noarch                                                                                                                         8/40
Verifying  : perl-constant-1.27-2.el7.noarch                                                                                                                         9/40
Verifying  : perl-PathTools-3.40-5.el7.x86_64                                                                                                                       10/40
Verifying  : perl-Socket-2.010-5.el7.x86_64                                                                                                                         11/40
Verifying  : 1:mariadb-5.5.65-1.el7.x86_64                                                                                                                          12/40
Verifying  : 1:perl-parent-0.225-244.el7.noarch                                                                                                                     13/40
Verifying  : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                                                                                                             14/40
Verifying  : perl-Net-Daemon-0.48-5.el7.noarch                                                                                                                      15/40
Verifying  : 4:perl-libs-5.16.3-295.el7.x86_64                                                                                                                      16/40
Verifying  : perl-File-Temp-0.23.01-3.el7.noarch                                                                                                                    17/40
Verifying  : 1:perl-Pod-Simple-3.28-4.el7.noarch                                                                                                                    18/40
Verifying  : perl-Time-Local-1.2300-2.el7.noarch                                                                                                                    19/40
Verifying  : perl-Text-ParseWords-3.29-4.el7.noarch                                                                                                                 20/40
Verifying  : perl-DBI-1.627-4.el7.x86_64                                                                                                                            21/40
Verifying  : libaio-0.3.109-13.el7.x86_64                                                                                                                           22/40
Verifying  : 4:perl-macros-5.16.3-295.el7.x86_64                                                                                                                    23/40
Verifying  : 4:perl-5.16.3-295.el7.x86_64                                                                                                                           24/40
Verifying  : perl-Carp-1.26-244.el7.noarch                                                                                                                          25/40
Verifying  : perl-Data-Dumper-2.145-3.el7.x86_64                                                                                                                    26/40
Verifying  : perl-Storable-2.45-3.el7.x86_64                                                                                                                        27/40
Verifying  : perl-Scalar-List-Utils-1.27-248.el7.x86_64                                                                                                             28/40
Verifying  : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                                                                                                            29/40
Verifying  : perl-Pod-Usage-1.63-3.el7.noarch                                                                                                                       30/40
Verifying  : perl-PlRPC-0.2020-14.el7.noarch                                                                                                                        31/40
Verifying  : perl-Encode-2.51-7.el7.x86_64                                                                                                                          32/40
Verifying  : perl-Pod-Perldoc-3.20-4.el7.noarch                                                                                                                     33/40
Verifying  : perl-podlators-2.5.1-3.el7.noarch                                                                                                                      34/40
Verifying  : perl-File-Path-2.09-2.el7.noarch                                                                                                                       35/40
Verifying  : perl-threads-1.87-4.el7.x86_64                                                                                                                         36/40
Verifying  : perl-Filter-1.49-3.el7.x86_64                                                                                                                          37/40
Verifying  : perl-Getopt-Long-2.40-3.el7.noarch                                                                                                                     38/40
Verifying  : 1:mariadb-libs-5.5.65-1.el7.x86_64                                                                                                                     39/40
Verifying  : 1:mariadb-libs-5.5.60-1.el7_5.x86_64                                                                                                                   40/40
Installed:
mariadb-server.x86_64 1:5.5.65-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7                mariadb.x86_64 1:5.5.65-1.el7                perl.x86_64 4:5.16.3-295.el7          perl-Carp.noarch 0:1.26-244.el7
perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7  perl-DBD-MySQL.x86_64 0:4.023-6.el7   perl-DBI.x86_64 0:1.627-4.el7
perl-Data-Dumper.x86_64 0:2.145-3.el7         perl-Encode.x86_64 0:2.51-7.el7              perl-Exporter.noarch 0:5.68-3.el7     perl-File-Path.noarch 0:2.09-2.el7
perl-File-Temp.noarch 0:0.23.01-3.el7         perl-Filter.x86_64 0:1.49-3.el7              perl-Getopt-Long.noarch 0:2.40-3.el7  perl-HTTP-Tiny.noarch 0:0.033-3.el7
perl-IO-Compress.noarch 0:2.061-2.el7         perl-Net-Daemon.noarch 0:0.48-5.el7          perl-PathTools.x86_64 0:3.40-5.el7    perl-PlRPC.noarch 0:0.2020-14.el7
perl-Pod-Escapes.noarch 1:1.04-295.el7        perl-Pod-Perldoc.noarch 0:3.20-4.el7         perl-Pod-Simple.noarch 1:3.28-4.el7   perl-Pod-Usage.noarch 0:1.63-3.el7
perl-Scalar-List-Utils.x86_64 0:1.27-248.el7  perl-Socket.x86_64 0:2.010-5.el7             perl-Storable.x86_64 0:2.45-3.el7     perl-Text-ParseWords.noarch 0:3.29-4.el7
perl-Time-HiRes.x86_64 4:1.9725-3.el7         perl-Time-Local.noarch 0:1.2300-2.el7        perl-constant.noarch 0:1.27-2.el7     perl-libs.x86_64 4:5.16.3-295.el7
perl-macros.x86_64 4:5.16.3-295.el7           perl-parent.noarch 1:0.225-244.el7           perl-podlators.noarch 0:2.5.1-3.el7   perl-threads.x86_64 0:1.87-4.el7
perl-threads-shared.x86_64 0:1.43-6.el7
Dependency Updated:
mariadb-libs.x86_64 1:5.5.65-1.el7
Complete!
[root@hostname ~]#

MariaDB Database Server Configuration

In this part, after finishing all of the installation process, the next step is to configure the database furthermore. Actually, the configuration process continue on by activating the MariaDB database server’s service by executing the following command :

[root@hostname ~]# systemctl start mariadb.service

After activating the service, the next configuration step is to activate the service on server’s booting or during server startup process. The main purpose for doing this is to avoid starting the MariaDB database server manually as in the above step. So, it will automatically activate and running in the booting or startup process. Usually, just execute the following command is the way to achieve it :

[root@hostname ~]# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@hostname ~]#

Furthermore, another step is to implement the security configuration by running a shell script available after the installation process. Just run the following command :

[root@hostname ~]# mysql_secure_installation
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):
OK, successfully used password, moving on...
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!

[First of all, the output above is ‘Y’ because when the installation is done, the root password need to be set.]

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!

[For the second one, the above input parameter is also ‘Y’ because of the security reason, ‘anonymous users’ cannot exist inside the database.]

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
... Success!

[For the next one, the above input is also in ‘Y’ because of root user also for a security reason it will be very dangerous to allow and use it from outside of the server using a remote access.]

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!

[Furthermore, just pass the ‘Y’ input in the end of the configuration part as an option to erase the database with the name of ‘test’. This is also for a security reason.]

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!

[Last one, after everything is done, the last input is also ‘Y’ to reload all of the changes in term of previlege.]

Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@hostname ~]#

MariaDB Database Server Firewall Configuration

Next part, after configuring MariaDB database from the security aspect is done, the next step is to manage the firewall configuration so that MariaDB firewall can be accessed from outside the server with the associated user. The following is the command to add port number 3306 as an execption so that it can be accessed without having the firewall block it :

[root@hostname ~]# systemctl status firewalld
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-09-13 23:53:32 UTC; 2 weeks 0 days ago
Docs: man:firewalld(1)
Main PID: 25364 (firewalld)
CGroup: /system.slice/firewalld.service
└─25364 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid
Sep 13 23:53:32 hostname systemd[1]: Starting firewalld - dynamic firewall daemon...
Sep 13 23:53:32 hostname systemd[1]: Started firewalld - dynamic firewall daemon.
Sep 13 23:53:32 hostname firewalld[25364]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will... it now.
Sep 13 23:54:09 hostname firewalld[25364]: WARNING: AllowZoneDrifting is enabled. This is considered an insecure configuration option. It will... it now.
Hint: Some lines were ellipsized, use -l to show in full.
[root@hostname ~]# firewall-cmd --list-port
8080/tcp
[root@hostname ~]#

Apparently, there is only one port available in the list and it is not MariaDB database port. In that case, just add it so that it will not blocked by the firewall of the operating system. The following is the command to add MariaDB database port number 3306 :

[root@hostname ~]# firewall-cmd --add-port=3306/tcp --permanent
success
[root@hostname ~]# firewall-cmd --reload
success
[root@hostname ~]# firewall-cmd --list-port
8080/tcp 3306/tcp
[root@hostname ~]#

Finally, after executing the above command, the process for installing MariaDB database server is actually finished.

Leave a Reply