How To Install MariaDB on CentOS Stream 9

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.

Create a MariaDB Repository File

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 - created 2023-11-01 14:20 UTC
# 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 <package-signing-key@mariadb.org>"
 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 <signing-key@mariadb.org>"
 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:

[root@vps ~]# mysql -V
mysql  Ver 15.1 Distrib 10.11.5-MariaDB, for Linux (x86_64) using  EditLine wrapper
[root@vps ~]#

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:

[root@vps ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.11.5 database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; preset: disabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Wed 2023-11-01 14:29:08 UTC; 1s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 64891 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUC>
    Process: 64892 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin>
    Process: 64917 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SU>
   Main PID: 64901 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 16 (limit: 23180)
     Memory: 85.7M
        CPU: 160ms
     CGroup: /system.slice/mariadb.service
             └─64901 /usr/sbin/mariadbd

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:

[root@vps ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.11.5-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)]>

Creating a new database and new user with password

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

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

mysql -u root -p

CREATE DATABASE crowncloud;

CREATE user username;

GRANT ALL ON crowncloud.* TO username@localhost IDENTIFIED BY 'password';

exit

This concludes our topic of installing MariaDB on CentOS Stream 9 system.