Saturday, December 28, 2024
Google search engine
HomeData Modelling & AIInstall MariaDB 10.7 on CentOS 8 | Rocky Linux 8

Install MariaDB 10.7 on CentOS 8 | Rocky Linux 8

Deploying the right database management system is one of your business success metric. With Plenty of RDMS available to choose from, it can be confusing to some extent picking the right one. MariaDB is an open source and successful project forked from MySQL relational database management system. It has support from hundreds of contributors, most being companies that rely on MariaDB heavily to power their business operations. MariaDB maintains high compatibility with MySQL with library binary parity and exact API and commands matching with MySQL.

In this brief tutorial we shall perform an installation of single node, master, MariaDB 10.7 on CentOS 8 | Rocky Linux 8 Linux system. For highly available deployments, you can explore the MariaDB Galera Cluster project. MariaDB 10.7 comes with the following new set of features;

  • New UUID Data Type – There is a new UUID data type aimed at the storage of 128-bit UUID (Universally Unique Identifier) data.
  • Updates in InnoDB – New improvements and features in the MariaDB InnoDB storage engine
  • Addition of Provider Plugins – There are five provider plugins (bzip2, lzma, lz4, lzo, snappy) for compression functionalities.
  • Natural Sort – To be used in ordering of strings in alphabetical order
  • New SFORMAT function
  • Password Reuse – The password_reuse_check plugin is a new password validation plugin
  • InnoDB Bulk Insert – In bulk insert, pre-sort and build indexes one page at a time
  • Diagnostics Property – Used to identify the affected row
  • For more details on new features available in MariaDB 10.7, check out the MariaDB Foundation release announcement page.

Install MariaDB 10.7 on CentOS 8 | Rocky Linux 8

Now that we’ve covered few basics on MariaDB database and new features in 10.7 release, We embark on the installation and configuration of MariaDB 10.7 on CentOS 8 | Rocky Linux 8.

1) Add MariaDB YUM repository

MariaDB team maintains YUM and APT repositories with stable and latest builds on MariaDB server and client packages. MariaDB server and Client packages are also available in the AppStream repository as modules in CentOS 8 | Rocky Linux 8 server. The only caveat is version.

$ sudo dnf module list mariadb
Last metadata expiration check: 1 day, 16:20:23 ago on Mon 22 Nov 2021 05:45:07 AM UTC.
Rocky Linux 8 - AppStream
Name                                       Stream                                      Profiles                                                      Summary
mariadb                                    10.3 [d]                                    client, galera, server [d]                                    MariaDB Module
mariadb                                    10.5                                        client, galera, server [d]                                    MariaDB Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

As seen from the output we only have version 10.5 and 10.3 of MariaDB in system repos.

Run the following commands to download MariaDB YUM repository setup script:

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

Run the script dowloaded while passing the relevant options to configure the repository.

sudo bash mariadb_repo_setup --mariadb-server-version=10.7

The script will automatically configure repo file and import GPG package signing keys

[info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
[info] Adding trusted package signing keys...
/etc/pki/rpm-gpg /home/rocky
/home/rocky
[info] Successfully added trusted package signing keys
[info] Cleaning package cache...
27 files removed

List configured repos

$ sudo dnf repolist
repo id                                                                                        repo name
appstream                                                                                      Rocky Linux 8 - AppStream
baseos                                                                                         Rocky Linux 8 - BaseOS
extras                                                                                         Rocky Linux 8 - Extras
mariadb-main                                                                                   MariaDB Server
mariadb-maxscale                                                                               MariaDB MaxScale
mariadb-tools                                                                                  MariaDB Tools

2) Install MariaDB 10.7 on CentOS 8 | Rocky Linux 8

MariaDB 10.7 packages can be installed from MariaDB repositories by running the following commands in your terminal

sudo dnf -y module reset mariadb
sudo dnf install MariaDB-server MariaDB-client MariaDB-backup

Confirm the version of MariaDB server and client packages being installed and proceed if okay.

Dependencies resolved.
======================================================================================================================================================================================================
 Package                                           Architecture                       Version                                                          Repository                                Size
======================================================================================================================================================================================================
Installing:
 MariaDB-backup                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                             7.0 M
 MariaDB-client                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              15 M
 MariaDB-server                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              25 M
Installing dependencies:
 MariaDB-common                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              88 k
 MariaDB-shared                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                             115 k
 boost-program-options                             x86_64                             1.66.0-10.el8                                                    appstream                                140 k
 galera-4                                          x86_64                             26.4.9-1.el8                                                     mariadb-main                              13 M
 libaio                                            x86_64                             0.3.112-1.el8                                                    baseos                                    31 k
 libpmem                                           x86_64                             1.6.1-1.el8                                                      appstream                                 78 k
 lsof                                              x86_64                             4.93.2-1.el8                                                     baseos                                   252 k
 perl-DBI                                          x86_64                             1.641-3.module+el8.4.0+509+59a8d9b3                              appstream                                739 k
 perl-Math-BigInt                                  noarch                             1:1.9998.11-7.el8                                                baseos                                   194 k
 perl-Math-Complex                                 noarch                             1.59-420.el8                                                     baseos                                   107 k
 socat                                             x86_64                             1.7.4.1-1.el8                                                    appstream                                322 k
Enabling module streams:
 perl-DBI                                                                             1.641

Transaction Summary
======================================================================================================================================================================================================
Install  14 Packages

Total download size: 62 M
Installed size: 288 M
Is this ok [y/N]: y

Details about the package can be checked with the rpm command:

$ sudo dnf info MariaDB-server
Last metadata expiration check: 0:02:30 ago on Tue 23 Nov 2021 10:13:33 PM UTC.
Installed Packages
Name         : MariaDB-server
Version      : 10.7.1
Release      : 1.el8
Architecture : x86_64
Size         : 119 M
Source       : MariaDB-server-10.7.1-1.el8.src.rpm
Repository   : @System
From repo    : mariadb-main
Summary      : MariaDB: a very fast and robust SQL database server
URL          : http://mariadb.org
License      : GPLv2
...

3) Start MariaDB 10.7 Server on CentOS 8 | Rocky Linux 8

MariaDB server service is not started automatically after the installation. You’ll need to start it by yourself

$ sudo systemctl enable --now mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

Status of the service can be validated using the command below:

$ systemctl status mariadb
 mariadb.service - MariaDB 10.7.1 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2021-11-23 22:17:40 UTC; 47s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 16703 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 16676 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSI>
  Process: 16674 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 16687 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 16 (limit: 49496)
   Memory: 68.0M
   CGroup: /system.slice/mariadb.service
           └─16687 /usr/sbin/mariadbd
...

The mariadb client command can also print server and client versions:

$ mariadb -V
mariadb  Ver 15.1 Distrib 10.7.1-MariaDB, for Linux (x86_64) using readline 5.1

4) Secure MariaDB server installation

With the default installation, MariaDB database server is not secured. The shell can be accessed without password as root user, and root user can login from a remote system. This is a security flaw especially in Production environment setup.

Run provided script that helps you harden MariaDB server via interactive prompts

$ sudo mariadb-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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): <ENTER>
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password: <INPUT-PASSWORD>
Re-enter new password: <CONFIRM-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, 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!

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!

If you try login as root user without password it should fail with an error message.

$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

Access with a password works

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.7.1-MariaDB MariaDB Server

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)]>

5) Create a test database/user in MariaDB

To create a database, let’s say testdb, run the command:

CREATE DATABASE testdb;

Check if the database has been created by showing all available databases.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.000 sec)

MariaDB is a good alternative to other commercial database management systems. We hope our guide enabled you to install MariaDB 10.7 on CentOS 8 | Rocky Linux 8 server or Desktop machine. We’re humbled by your continual support, stay blessed!.

Good Udemy Learning courses:
RELATED ARTICLES

Most Popular

Recent Comments