Introduction:
MariaDB is an open-source relational database management system and a popular alternative to MySQL. It is known for its performance, security, and ease of use. In this tutorial, we will guide you through the process of installing and configuring MariaDB on CentOS 8, a popular Linux distribution.
Step 1: Update CentOS 8
Before we begin, it’s essential to ensure that your system is up-to-date. Open a terminal and run the following commands:
sudo dnf update
This will update the package list and upgrade your system’s packages to the latest versions.
Step 2: Install MariaDB
To install MariaDB on CentOS 8, use the following command:
sudo dnf install mariadb-server
This command will download and install MariaDB and its dependencies.
Step 3: Start and Enable MariaDB
Once the installation is complete, you need to start the MariaDB service and enable it to start at boot time:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Step 4: Secure MariaDB
Run the security script to enhance the security of your MariaDB installation:
sudo mysql_secure_installation
Follow the on-screen prompts and answer the questions to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload the privilege tables.
Step 5: Access MariaDB
You can access the MariaDB shell by running:
sudo mysql -u root -p
You will be prompted to enter the root password you set earlier during the secure installation.
Step 6: Create a Database and User
Let’s create a new database and user for demonstration purposes:
CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
Replace 'mydb'
, 'myuser'
, and 'mypassword'
with your preferred database name, username, and password.
Step 7: Exit MariaDB
To exit the MariaDB shell, type:
exit
Step 8: Test the New Database
You can now log in to the MariaDB shell using the newly created user:
mysql -u myuser -p
Enter the password when prompted.
Conclusion
Congratulations! You have successfully installed and configured MariaDB on CentOS 8. You can now start using MariaDB to build and manage your databases. Make sure to keep your MariaDB installation up-to-date and follow best practices for database security to ensure the safety of your data.