How To Install MariaDB on AlmaLinux 8

MariaDB is a popular, free and open-source database management system.

Installing MariaDB Server

yum install mariadb-server

Output:

[root@vps ~]# yum install mariadb-server
Last metadata expiration check: 1:22:17 ago on Mon 31 May 2021 09:07:36 AM EDT.
Dependencies resolved.
================================================================================
 Package                    Arch   Version                      Repo       Size
================================================================================
Installing:
 mariadb-server             x86_64 3:10.3.28-1.module_el8.3.0+2177+7adc332a
                                                                appstream  16 M
Installing dependencies:
 libaio                     x86_64 0.3.112-1.el8                baseos     32 k
 mariadb                    x86_64 3:10.3.28-1.module_el8.3.0+2177+7adc332a
                                                                appstream 6.0 M

Check the version of mariadb server by following command.

mysql -V

Output:

[root@vps ~]# mysql -V
mysql  Ver 15.1 Distrib 10.3.28-MariaDB, for Linux (x86_64) using readline 5.1

Once the installation is complete, 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.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
   Active: active (running) since Mon 2021-05-31 10:31:17 EDT; 1s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 4093 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, st>
  Process: 3959 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mariadb.service >
  Process: 3934 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, stat>
 Main PID: 4062 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 11435)

Next, To secure your MariaDB server.

You must secure the MariaDB server by running the following command for production use.

mysql_secure_installation

Output:

[root@vps ~]# 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!

Now, log in to the MariaDB server.

To login to the MariaDB server, enter the following command with the password 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 16
Server version: 10.3.28-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 new database, new database user and access the database.

Here We'll look to create new database, new database user and add the user to database. (eg: Here we'll cerate database called "crowncloud" and the new user called "ccuser1")

First, log in as root user:

mysql -u root -p

CREATE DATABASE crowncloud;

CREATE user ccuser1;

GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'secretePasswordHere';

Output:

[root@vps ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.3.17-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)]> CREATE DATABASE crowncloud;
Query OK, 1 row affected (0.002 sec)

MariaDB [(none)]> CREATE user ccuser1;
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'secretePasswordHere';
Query OK, 0 rows affected (0.004 sec)

Here we'll access to the database by the database user.

mysql -u ccuser1 -p'secretePasswordHere' crowncloud

show databases;

Output:

[root@vps ~]# mysql -u ccuser1 -p'secretePasswordHere' crowncloud
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 10.3.28-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 [crowncloud]> show databases;
+--------------------+
| Database           |
+--------------------+
| crowncloud         |
| information_schema |
+--------------------+
2 rows in set (0.002 sec)

MariaDB [crowncloud]>