Friday, November 15, 2024
Google search engine
HomeData Modelling & AIInstall MariaDB 10.7 on AlmaLinux 8|Oracle Linux 8

Install MariaDB 10.7 on AlmaLinux 8|Oracle Linux 8

MariaDB is a free and open-source, commercially supported relational database management system. It is a fork of the MySQL database system invented due to the fear of MySQL acquisition by Oracle Inc and making it a paid service. Ever since its invention in 2009, MariaDB has gained popularity and serves as the best drop-in replacement for MySQL. MariaDB being a fork of the MySQL database system, maintains high compatibility with MySQL library binary parity and API commands.

MariaDB 10.7 is the latest release version for this relational database system. It comes with a lot of amazing features such as:

  • Compression provider plugins
  • A function for natural sorting of strings
  • Password reuse prevention plugin
  • Updates in InnoDB – New improvements and features in the MariaDB InnoDB storage engine
  • JSON Histograms: improve histogram collection
  • InnoDB Bulk Insert – In bulk insert, pre-sort and build indexes one page at a time
  • The ability to convert table to partition and vice-versa
  • Custom formatting of strings in MariaDB queries
  • Addition of Provider Plugins – There are five provider plugins (bzip2, lzma, lz4, lzo, snappy) for compression functionalities.
  • UUID data type

In this guide, we will walk systematically through how to install MariaDB 10.7 on AlmaLinux 8|Oracle Linux 8

Getting Started.

Before we dive into the installation, ensure your system packages are updated to the latest available stable versions.

sudo yum update

Step 1 – Add MariaDB YUM repository on AlmaLinux 8|Oracle Linux 8

MariaDB APT and YUM repositories are maintained and updated with the latest MariaDB server and client packages, this makes it easy to install and update your MariaDB version.

Check the available versions in the system repositories:

$ sudo dnf module list mariadb
Oracle Linux 8 Application Stream (x86_64)
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

To be able to install MariaDB 10.7 onAlmaLinux 8|Oracle Linux 8 we need to add the MariaDB YUM repository below to our system.

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.7

Sample output after command execution:

[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/thor
/home/thor
[info] Successfully added trusted package signing keys
[info] Cleaning package cache...
219 files removed

Now that the repository has been configured and GPG signing keys imported as well, we will check if the repo has been successfully added.

$ sudo dnf repolist
repo id                                                                repo name
mariadb-main                                                           MariaDB Server
mariadb-maxscale                                                       MariaDB MaxScale
mariadb-tools                                                          MariaDB Tools
ol8_UEKR6                                                              Latest Unbreakable Enterprise Kernel Release 6 for Oracle Linux 8 (x86_64)
ol8_appstream                                                          Oracle Linux 8 Application Stream (x86_64)
ol8_baseos_latest                                                      Oracle Linux 8 BaseOS Latest (x86_64)
ol8_developer_EPEL                                                     Oracle Linux 8 EPEL (x86_64)

Step 2 – Install MariaDB 10.7 onAlmaLinux 8|Oracle Linux 8

Once the repository has been added to the system, installing MariaDB is an easy task that can be accomplished as below.

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

Dependency Tree:

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
 galera-4             x86_64       26.4.9-1.el8        mariadb-main        13 M
 socat                x86_64       1.7.4.1-1.el8       appstream          322 k

Transaction Summary
================================================================================
Install  7 Packages

Total download size: 60 M
Installed size: 284 M
Is this ok [y/N]: y

Once the installation is complete, verify the installed version of MariaDB.

$ sudo dnf info MariaDB-server
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
Description  : MariaDB: a very fast and robust SQL database server
             : 
             : It is GPL v2 licensed, which means you can use the it free of
             : charge under the conditions of the GNU General Public License
             : Version 2 (http://www.gnu.org/licenses/).
             : 
             : MariaDB documentation can be found at https://mariadb.com/kb
             : MariaDB bug reports should be submitted through
             : https://jira.mariadb.org

Step 3 – Manage MariaDB 10.7 onAlmaLinux 8|Oracle Linux 8

Start and enable MariaDB service.

sudo systemctl enable --now mariadb

Check the status of the service:

$ 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 Sun 2021-12-05 02:40:44 EST; 11s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 32909 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 32885 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] >
  Process: 32883 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 32895 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 14 (limit: 36438)
   Memory: 62.9M
   CGroup: /system.slice/mariadb.service
           └─32895 /usr/sbin/mariadbd

The MariaDB service can be restarted as below.

sudo systemctl restart mariadb

Step 4 – Secure MariaDB Installation onAlmaLinux 8|Oracle Linux 8

Once installed, the MariaDB instance is not hardened, we, therefore, need to make changes as below and set the root password.

sudo mariadb-secure-installation

Proceed as shown.

Enter current password for root (enter for none): Press Enter
....
Switch to unix_socket authentication [Y/n] y
.......
Change the root password? [Y/n] y
New password: Enter Password
Re-enter new password: Re-Enter Password
......
Remove anonymous users? [Y/n] y
...
Disallow root login remotely? [Y/n] y
...
Remove test database and access to it? [Y/n] y
....
Reload privilege tables now? [Y/n] y
.....
Thanks for using MariaDB!

Step 5 – Use MariaDB 10.7 onAlmaLinux 8|Oracle Linux 8

We will now proceed and test the installed MariaDB 10.7. Begin by login into the MariaDB shell.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 32
Server version: 10.6.3-MariaDB-1:10.6.3+maria~buster mariadb.org binary distribution

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)]> SELECT VERSION ();
+----------------+
| VERSION ()     |
+----------------+
| 10.7.1-MariaDB |
+----------------+
1 row in set (0.000 sec)

MariaDB [(none)]> exit
Bye

1. Create a user in MariaDB 10.7

Below is a list of commands you can use to create users and assign the required permissions.

#Create user mariadb
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
GRANT ALL PRIVILEGES ON 'testdb'.* TO 'myuser'@'localhost';

#Grant privileges to all databases
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';

#Remember to refresh the privileges
FLUSH privileges;

#To check user grants in MariaDB
SHOW GRANTS FOR 'myuser'@'locahost';

2. Create a Database in MariaDB 10.7

We will create a sample database say, testdb

CREATE DATABASE testdb;

If the database exists, you can replace it aa below.

CREATE OR REPLACE DATABASE testdb;

Verify the database creation.

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

3. Create a Table and add data to it in MariaDB 10.7

To the created database, we can create a table and insert data into it as below.

USE testdb;
CREATE TABLE clients (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO clients (id,name,email) VALUES(01,"thor","[email protected]");

Show tables in the database:

MariaDB [testdb]> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| clients          |
+------------------+
1 row in set (0.001 sec)

In the table, show columns as below.

MariaDB [testdb]> SHOW COLUMNS FROM clients;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
| email | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)

Once you have completed the intended tasks on MariaDB, you can exit the shell as shown:

MariaDB [testdb]> exit
Bye

Step 6 – Remove/Uninstall MariaDB onAlmaLinux 8|Oracle Linux 8

MariaDB can be uninstalled on using the commands:

##Remove data from MariaDB
sudo rm -rf /var/lib/mysql/

##Uninstall MariaDB
sudo yum autoremove mariadb-server mariadb-client

Sample Output:

Dependencies resolved.
================================================================================
 Package             Arch        Version               Repository          Size
================================================================================
Removing:
 MariaDB-server      x86_64      10.7.1-1.el8          @mariadb-main      119 M
Removing unused dependencies:
 galera-4            x86_64      26.4.9-1.el8          @mariadb-main       61 M
 socat               x86_64      1.7.4.1-1.el8         @appstream         1.2 M

Transaction Summary
================================================================================
Remove  3 Packages

Freed space: 181 M
Is this ok [y/N]: y

Conclusion.

That is enough learning! This guide on how to install MariaDB 10.7 onAlmaLinux 8|Oracle Linux 8 Linux system was delivered with the hope of being a success. If you encountered trouble in setting it up, let us know in the comments.

See more:

How To Install MariaDB 10.7 on CentOS 7 / RHEL 7

How To Install MariaDB 10.7 on Debian 11 / Debian 10

How To Install MariaDB 10.7 on Ubuntu 20.04|18.04

RELATED ARTICLES

Most Popular

Recent Comments