How to install MariaDB on CentOS 9 Stream

Estimated reading: 3 minutes 637 views

Introduction

MariaDB is an open-source relational database management system (DBMS) that is a compatible drop-in replacement for the widely used MySQL database technology. MariaDB is based on SQL and supports ACID-style data processing with guaranteed atomicity, consistency, isolation, and durability for transactions.

In this article, we will show you how to install MariaDB on a CentOS 9 stream server/VPS instance.

Prerequisite: 

  • An active KVM VPS
  • root user

Install MariaDB 

To install the MariaDB server, you need to create a MariaDB repository configuration file mariadb.repo manually with this path ‘/etc/yum.repos.d/’

To create a MariaDB repository file, you can use the following command,

vi /etc/yum.repos.d/mariadb.repo

The above command will create a new repository file, Once it is created, you need to add the following configurations in that file,

# MariaDB 10.11 RedHatEnterpriseLinux repository list 
# https://mariadb.org/download/
[mariadb]
name = MariaDB
# rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
# baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch
baseurl = https://mirror.23m.com/mariadb/yum/10.11/rhel/$releasever/$basearch
# gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB
gpgkey = https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1

Save and exit file.

Installing MariaDB Server

dnf install MariaDB-server MariaDB-client

You will be presented with a series of prompts. Here’s what you’ll be asked and how to respond:

Install  78 Packages

Total download size: 39 M
Installed size: 265 M
Is this ok [y/N]: y

Total                                                                                   6.5 MB/s |  39 MB     00:06
MariaDB                                                                                  17 kB/s |  15 kB     00:00
Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <[email protected]>"
 Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
 From       : https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y
Key imported successfully
Importing GPG key 0xC74CD1D8:
 Userid     : "MariaDB Signing Key <[email protected]>"
 Fingerprint: 177F 4010 FE56 CA33 3630 0305 F165 6F24 C74C D1D8
 From       : https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y

Once the installation is complete, you can verify the version of the MariaDB server by using the following command:

mysql -V

Output:

Screenshot of GIT post-compilation on CentOS Stream el9 or el8.

Now, enable MariaDB (to start automatically upon system boot), start the MariaDB and verify the status using the commands below

systemctl enable mariadb

systemctl start mariadb

systemctl status mariadb

Output:

Screenshot of GIT post-compilation on CentOS Stream el9 or el8.

Secure your MariaDB server

You can secure your MariaDB installation by following these steps

Start the MariaDB shell:

mysql

Change the root user’s password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';

Replace ‘your_new_password’ with the password you want to set for the root user.

Remove anonymous users:

DELETE FROM mysql.user WHERE User='';

Disallow remote root login. This ensures that the root user can only log in from the localhost:

DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');

Remove the test database:

DROP DATABASE IF EXISTS test;

Reload the privileges to apply the changes:

FLUSH PRIVILEGES;

Exit the MariaDB shell:

EXIT;

Access MariaDB server

To login to the MariaDB server, enter the following command with the password that was set previously,

mysql -u root -p

Output:

Screenshot of GIT post-compilation on CentOS Stream el9 or el8.

Creating a new database and new user with a password

Let’s create a new database with a custom user and password.

First, log in as root user, then type the following commands:

mysql -u root -p

CREATE DATABASE greencloud;

CREATE user green;

GRANT ALL ON greencloud.* TO green@localhost IDENTIFIED BY 'password';

exit

That’s it! Enjoy GreenCloudVPS services!

Leave a Comment