{"id":73239,"date":"2022-12-30T11:30:00","date_gmt":"2022-12-30T16:30:00","guid":{"rendered":"https:\/\/jumpcloud.com\/?p=73239"},"modified":"2023-01-06T11:06:32","modified_gmt":"2023-01-06T16:06:32","slug":"how-to-install-mariadb-rhel-9","status":"publish","type":"post","link":"https:\/\/jumpcloud.com\/blog\/how-to-install-mariadb-rhel-9","title":{"rendered":"How to Install and Secure MariaDB in RHEL 9"},"content":{"rendered":"\n
Jump to Tutorial<\/a><\/p>\n\n\n\n MariaDB<\/a> is an open source and community-developed fork of MySQL. It is a widely used relational database management system<\/a> (RDMS) used to store data both in production and for personal and experimental projects. It was designed by the original developers of the MySQL database server, with the objective of remaining open source under the GNU GPL license.<\/p>\n\n\n\n Some of the advantages of using MariaDB over MySQL include:<\/p>\n\n\n\n In this guide, we will demonstrate how to install and secure MariaDB on RHEL 9.<\/p>\n\n\n\n To get started, log into your server as a sudo user via SSH. Next, upgrade all the packages and refresh the repositories as follows:<\/p>\n\n\n\n The MariaDB Server package is provided by the official AppStream repositories. You can confirm this by searching for the package on the repositories as shown:<\/p>\n\n\n\n The following output confirms that MariaDB is hosted on the default repositories.<\/p>\n\n\n\n The next step is to install the MariaDB Server. To do so, run the following command:<\/p>\n\n\n\n The command installs the MariaDB server alongside other dependencies and additional packages required by the database server.<\/p>\n\n\n\n Once the installation is complete, confirm that MariaDB is installed using the following command:<\/p>\n\n\n\n Running this command displays comprehensive details about the MariaDB Server package including the name, version, architecture, installation date, and installed size to name a few.<\/p>\n\n\n\n Up to this point, we have successfully installed the MariaDB Server. By default, the MariaDB service does not start automatically. As such you need to start it by running the following command:<\/p>\n\n\n\n In addition, set it to start automatically on system startup.<\/p>\n\n\n\n To verify that MariaDB is up and running, run the command:<\/p>\n\n\n\n MariaDB listens on TCP port 3306. You can confirm this using the command:<\/p>\n\n\n\n The default settings for the MariaDB database server are considered weak and not robust in the face of a breach or intrusion. As such, you need to go an extra step and secure the database server. To do this, run the Running the script will present you with a series of prompts.<\/p>\n\n\n\n First, you will be required to provide the root password. Next, switch to unix_socket authentication<\/strong> which allows the user to use operating system credentials when connecting to the MariaDB database server.<\/p>\n\n\n\n You can then decide to change the root user or let it remain exactly the way it is.<\/p>\n\n\n\n For the remaining prompts, press \u201cY\u201d in order to secure MariaDB to the recommended standards. This does the following:<\/p>\n\n\n\n MariaDB is now secured using the recommended security standards after installation.<\/p>\n\n\n\n To log in to the MariaDB database server, run the command:<\/p>\n\n\n\n Provide the root password for MariaDB and press ENTER. This ushers you to the MariaDB shell.<\/p>\n\n\n\n To check the version of MariaDB installed, run the command:<\/p>\n\n\n\n From the output, you can see that we are running MariaDB 10.5.16.<\/p>\n\n\n\n To list all the databases, run the command:<\/p>\n\n\n\n This step illustrates how to create a database and a database user.<\/p>\n\n\n\n To create a database in the MariaDB Server, run the following command where Next, create a database user on the system with a password. Here, Next, grant privileges to the database user on the database. This determines the rights that the user has on the database, e.g., ALTER, CREATE, DELETE, DROP, SELECT, UPDATE, etc. This command will grant user rights to the database.<\/p>\n\n\n\n Lastly, reload the grant tables in order to save the changes made as follows:<\/p>\n\n\n\n To confirm the creation of the database, again, run the following SQL query:<\/p>\n\n\n\n This time around, an additional database named To view a list of all the users in the database server, run the following query:<\/p>\n\n\n\n In this guide, you learned how to install and secure the MariaDB database server on RHEL 9. For more information about MariaDB, check out the official documentation<\/a>.<\/p>\n\n\n\n Looking for more ways to secure your Linux servers and devices? Learn how to improve Linux security posture<\/a> with JumpCloud’s MDM policies. <\/p>\n\n\n\n\n\n
Step 1: Upgrade Software Packages<\/h2>\n\n\n\n
$ sudo dnf update<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo dnf search mariadb-server<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Step 2: Install MariaDB Server on RHEL 9<\/h2>\n\n\n\n
$ sudo dnf install mariadb-server -y<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
$ rpm -qi mariadb-server<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Step 3: Start and Enable MariaDB Server<\/h2>\n\n\n\n
$ sudo systemctl start mariadb<\/code><\/p>\n\n\n\n
$ sudo systemctl enable mariadb<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo systemctl status mariadb<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
$ sudo ss -pnltu | grep mariadb<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Step 4: Secure MariaDB Server<\/h2>\n\n\n\n
mysql_secure_installation<\/code> script as shown:<\/p>\n\n\n\n
$ sudo mysql_secure_installation<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
\n
<\/figure>\n\n\n\n
Step 5: Log Into MariaDB Server<\/h2>\n\n\n\n
$ sudo mysql -u root -p<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
SELECT VERSION();<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
SHOW DATABASES;<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Step 6: Create Database and Database User (Optional)<\/h2>\n\n\n\n
test_db <\/code>is the database name:<\/p>\n\n\n\n
CREATE DATABASE test_db;<\/code><\/p>\n\n\n\n
test_user <\/code>is the name of the database user and
P@ssword321@ <\/code>is the user\u2019s password. Be sure to provide a stronger password for your user.<\/p>\n\n\n\n
CREATE USER ‘test_user’@’localhost’ IDENTIFIED BY ‘Password321@’;<\/code><\/p>\n\n\n\n
GRANT ALL ON test_db.* TO ‘test_user’@’localhost’ WITH GRANT OPTION;<\/code><\/p>\n\n\n\n
FLUSH PRIVILEGES<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
SHOW DATABASES;<\/code><\/p>\n\n\n\n
test_db <\/code>appears on the list.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
SELECT User, Host FROM mysql.user;<\/code><\/p>\n\n\n\n
<\/figure>\n\n\n\n
Conclusion<\/h2>\n\n\n\n