How To Install MariaDB on Rocky Linux 9
MariaDB is a popular, free, and open-source database management system.
Installing MariaDB Server
Installing MariaDB on Rocky Linux is simple and easy with the dnf
package manager.
Just run the following command,
dnf install mariadb-server
Output:
[root@server ~]# dnf install mariadb-server
Last metadata expiration check: 0:10:26 ago on Mon 18 Jul 2022 05:01:51 PM CEST.
Dependencies resolved.
======================================================================================
Package Arch Version Repository Size
======================================================================================
Installing:
mariadb-server x86_64 3:10.5.13-2.el9 appstream 9.3 M
Installing dependencies:
libaio x86_64 0.3.111-13.el9 baseos 23 k
mariadb x86_64 3:10.5.13-2.el9 appstream 1.6 M
mariadb-common x86_64 3:10.5.13-2.el9 appstream 32 k
mariadb-connector-c x86_64 3.2.6-1.el9_0 appstream 195 k
mariadb-connector-c-config noarch 3.2.6-1.el9_0 appstream 9.8 k
mariadb-errmsg x86_64 3:10.5.13-2.el9 appstream 188 k
mysql-selinux noarch 1.0.4-2.el9 appstream 35 k
perl-AutoLoader noarch 5.74-479.el9 appstream 30 k
Check the version of the MariaDB server by the following command.
mysql -V
Output:
[root@server ~]# mysql -V
mysql Ver 15.1 Distrib 10.5.13-MariaDB, for Linux (x86_64) using EditLine wrapper
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 preset: di>
Active: active (running) since Mon 2022-07-18 17:17:45 CEST; 16ms ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 5098 ExecStartPre=/usr/libexec/mariadb-check-socket (code=exited, status=0/>
Process: 5120 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir mariadb.service (code>
Process: 5215 ExecStartPost=/usr/libexec/mariadb-check-upgrade (code=exited, status=>
Main PID: 5202 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 12 (limit: 11120)
Memory: 76.8M
CPU: 556ms
CGroup: /system.slice/mariadb.service
└─5202 /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 13
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 add the user to the database. (eg: Here we'll create a 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 13
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)
Access 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!