How to Install and Configure MariaDB on CentOS/RHEL 7

How to Install and Configure MariaDB on CentOS/RHEL 7
mariadb setup 2024

This detailed guide will gently guide you through the process, making the installation and configuration of MariaDB a breeze, guaranteeing a strong and dependable database foundation for your system.

Step 1: Installing MariaDB

Begin by updating your system’s package repository and then installing MariaDB. Open a terminal and enter the following commands:

sudo yum update sudo yum install mariadb-server

Once the installation is complete, start the MariaDB service and enable it to start on boot:

sudo systemctl start mariadb sudo systemctl enable mariadb

Step 2: Securing Your MariaDB Installation

MariaDB comes with a script to enhance security. Run the following command and follow the prompts:

sudo mysql_secure_installation

This script allows you to set a root password, remove anonymous users, disallow remote root login, and more.

Step 3: Accessing MariaDB

Now, let’s access the MariaDB shell using the following command. You will be prompted for the root password you set earlier:

sudo mysql -u root -p

Step 4: Creating a New MariaDB User and Database

Inside the MariaDB shell, you can create a new database and user. Replace ‘database_name,’ ‘user_name,’ and ‘password’ with your preferred choices:

CREATE DATABASE database_name; CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON database_name.* TO 'user_name'@'localhost'; FLUSH PRIVILEGES;

Exit the MariaDB shell:

EXIT;

Step 5: Configuring MariaDB for Remote Access (Optional)

If you need to allow remote connections to MariaDB, you’ll need to modify the MariaDB configuration file. Open the configuration file in a text editor:

sudo nano /etc/my.cnf.d/server.cnf

Find the ‘bind-address’ line and replace ‘127.0.0.1’ with the IP address of your server. Save the file and restart MariaDB:

sudo systemctl restart mariadb

Congratulations! You’ve successfully installed and configured MariaDB on your CentOS/RHEL 7 system. Whether you’re setting up a database for a web application or other projects, MariaDB provides a reliable and efficient solution. Stay tuned for more tutorials from TutoSquad, guiding you through the intricate landscape of system administration and configuration.

Heinz Avatar