Choosing the right database for your application is not an easy task, but it is vital to the success of the application. MariaDB is a drop-in replacement for MySQL with additional features and better performance. Learn how to install or upgrade mariadb on CentOS 8 / RHEL 8 in this post!
MariaDB is a free and open source relational database management system. It is a fork of the popular MySQL database system. MariaDB is compatible with MySQL, which means that it can use all of the existing MySQL databases and tools. MariaDB is widely used in both production and development environments.
CentOS and RHEL are two popular Linux distributions. Both distributions use the RPM Package Manager (RPM) to install, update, and remove software packages. MariaDB is available in the RPM repository for both distributions.
In this guide, we will show you how to install MariaDB on CentOS 7 and RHEL 7. We will also show you how to create a new database and user, and how to grant privileges to the user.
Adding MariaDB Repository to Yum
To add the MariaDB repository to yum, you will need to install the MariaDB RPM package from the MariaDB website. You can do this by running the following command:
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
After running this command you will be able to install the latest version of MariaDB from the official MariaDB repository.
Installing MariaDB Server
Once the repository has been added, you can install MariaDB by running the following command:
yum install MariaDB-server MariaDB-client
How to Enable MariaDB Service to Start At Boot
To enable the MariaDB service to start automatically at boot, you’ll need to use the chkconfig command. You can do this by running the following command:
systemctl enable mariadb
This will enable the MariaDB service to start automatically whenever the server is rebooted.
How to Start MariaDB Service
The first thing you need to do is start the MariaDB service. You can do this by running the following command:
systemctl start mariadb
How to Secure MariaDB Server Installation
It is important to secure your MariaDB server installation to protect your data from being accessed by unauthorized users. One way to do this is to set a password for the root user. You can do this by running the following command:
Answer the questions the prompt gives you for best experience.
You will be prompted to enter a password for the root user, put your password there and make sure you copy it to a safe location, so you will not lose it.
Adding a New Database to The MariaDB Server
Adding a new database to the MariaDB server is a simple process. First, log in to the MariaDB server as root. Then, create a new database using the “CREATE DATABASE” command. For example, to create a new database named “new_db”, you would use the following command:
CREATE DATABASE new_db;
Creating a User And Granting It Permissions
In order to create a new user, log into the MariaDB shell as the root user and running the following commands:
Creating the user “new_user” and the password “password”:
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';
Granting permissions for the new user on the new database:
GRANT ALL PRIVILEGES ON new_db.* TO 'new_user'@'localhost' IDENTIFIED BY 'password';
Flushing privileges (saves privileges):
In this article, we have shown you how to install MariaDB on a AlmaLinux 8 or RHEL 8 server.
We also showed you how to create a new database and user, and how to grant the user permissions to access the database. Once you have MariaDB installed and configured on your server, you can begin working with databases and tables. Thanks for reading!