How To Install MariaDB on AlmaLinux 9
MariaDB is a popular, free, and open-source database management system.
Installing MariaDB Server
yum install mariadb-server
Output:
[root@server ~]# yum install mariadb-server
AlmaLinux 9.0-beta - BaseOS 7.4 kB/s | 3.9 kB 00:00
AlmaLinux 9.0-beta - AppStream 8.2 kB/s | 3.9 kB 00:00
AlmaLinux 9.0-beta - Extras packages 8.2 kB/s | 3.8 kB 00:00
Dependencies resolved.
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
mariadb-server x86_64 3:10.5.13-1.el9 appstream 9.3 M
Installing dependencies:
checkpolicy x86_64 3.3-1.el9 appstream 339 k
libaio x86_64 0.3.111-13.el9 baseos 23 k
mariadb x86_64 3:10.5.13-1.el9 appstream 1.6 M
mariadb-common x86_64 3:10.5.13-1.el9 appstream 27 k
mariadb-connector-c x86_64 3.2.6-1.el9_0 appstream 194 k
mariadb-connector-c-config noarch 3.2.6-1.el9_0 appstream 9.7 k
mariadb-errmsg x86_64 3:10.5.13-1.el9 appstream 183 k
Check the version of the MariaDB server by the following command.
mysql -V
Output:
[root@server ~]# mysql -v
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.13-MariaDB MariaDB Server
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@server ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.5 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor p>
Active: active (running) since Tue 2022-05-24 17:37:35 CEST; 57s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 2990 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, >
Process: 3012 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.serv>
Process: 3104 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited>
Main PID: 3092 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 5912)
Memory: 74.0M
CPU: 553ms
CGroup: /system.slice/mariadb.service
└─3092 /usr/libexec/mariadbd --basedir=/usr
Secure your MariaDB server
You must secure the MariaDB server by running the following command for production use.
mysql_secure_installation
Output:
[root@server ~]# 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
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
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:
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@server ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.13-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.
Create a new DataBase and User
Here, we'll look into creating a new database, new database user, and adding the user to the database. (eg: Here we'll create database called "crowncloud" and the new user called "ccuser1"),
mysql -u root -p
CREATE DATABASE crowncloud;
CREATE user ccuser1;
GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'secretePasswordHere';
Output:
[root@server ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 10.5.13-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.003 sec)
MariaDB [(none)]> GRANT ALL ON crowncloud.* TO ccuser1@localhost IDENTIFIED BY 'crown@';
Query OK, 0 rows affected (0.003 sec)
Accessing the database
Now, we will access MariaDB with the newly created Database and User as shown below,
mysql -u ccuser1 -p'secretePasswordHere' crowncloud
show databases;
Output:
[root@server ~]# mysql -u ccuser1 -p'crown@' crowncloud
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.5.13-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]>
DONE!