MariaDB is an open and free source backward compatible database management framework that works widely as a MySQL binary substitution. This is a branch created and based on the Oracle MySQL service community. It has multiple threads and is a multi-user SQL database server. It was developed by several of the original MySQL creators and other members of the community. MariaDB is the recommended distribution if you’re interested in comparing MySQL to MariaDB. It should also work flawlessly when replacing MySQL.
In this article, we are going to show you how to install and get started with MariaDB on Centos 8.
Steps to install MariaDB on Centos 8
First, make sure you have Centos 8 installed on your system. Now open a Terminal in Centos 8. Another option is to log in using the command user @ centos-8-server-ip ssh ssh. Then follow these three steps:
- Installing MariaDB on Centos 8
- Securing the Centos 8 MariaDB server
- Check installation
Let’s take a closer look at all the steps and commands.
Installing MariaDB on Centos 8
Use the following command to find the MariaDB package:
$ sudo yum search mariadb
After that, use the following command to find your MariaDB server version:
$ sudo yum info mariadb
The first step in the installation is to add the following ‘dnf’ or ‘yum’ command as root user:
$ sudo dnf install @mariadb
$ sudo dnf install @mariadb-server
$ sudo yum install mariadb-server
You will be prompted for your current account password to proceed with the installation.
You will then be asked to confirm your action to proceed. Type “y” and then press Enter. The @mariadb package will download the MariaDB server and all its plugins.
When the installation is complete, start the MariaDB service and allow it to instantly start the boot process by entering the command below added:
$ sudo systemctl enable --now mariadb
To verify that the MariaDB service is running, check the system status with the following command:
$ sudo systemctl status mariadb
The result should demonstrate that the system is up and running, as you can see in the attached image.
Securing the Centos 8 MariaDB server
MariaDB comes with a secure MySQL installation script that performs many security-related functions and defines the root password. Use this instruction to execute your security script:
$ sudo mysql_secure_installation
You will be prompted for your current account password to continue. You will then be prompted for a password for the MariaDB root account that has not been installed yet, so you must press ENTER as prompted. Note that it is for the database root account, not for the root account of the Centos server itself. To set a password for the root database user, press y followed by ENTER, then follow the instructions.
You must accept all security recommendations by pressing “y” and then ENTER after updating your password. It will remove anonymous users, disable remote root logins, erase the test database, and load the privilege tables.
Now, on your CentOS 8, you have already configured and secured MariaDB and it is ready to use.
You can check your installation and configuration, as well as detailed information on all of this, by contacting the mysqladmin program, a client that lets you work with administrative instructions. To connect through the console to the MariaDB server as root, enter the following instruction:
Mysql - root u –p
You may be asked for a password (-p) and the version will be displayed. A result similar to this should be shown as shown in the attached image.
The instructions above assume that the installation was active on the server. Now you can connect users and create databases for your applications.
First, login as root user using the below command. You will be prompted for your password.
$ mysql –u root –p mysql
Add new database
Create a new database for MariaDB named test. On the MariaDB command line, run the following instruction:
CREATE DATABASE test
Note You can set the database name of your choice.
Add new user
Create a new user for the test database named “student”. You can safely replace secretPasswordHere with the real password you want to add. Try this command to add a new user:
$ GRANT ALL ON test.* TO [email protected] IDENTIFIED BY 'secretePasswordHere';
Note You can set the new username in the database of your choice.
You can also check the list of all databases present in MariaDB using the following command:
$ show databases;
You can also quit MariaDB using a simple quit command as shown below:
Connect to MariaDB database
You can easily connect to the MariaDB database by running one of the following commands:
$ mysql –u student –p 'secretPasswordHere' test
$ mysql –u student –p test
This tutorial shows the process of installing and using MariaDB on Centos 8 and connecting it via the command line to a MariaDB server, and adding databases and users to it. Your MariaDB server is ready and ready to go. Now you can start creating new databases and users by connecting to the MariaDB shell. Centos 8 also provides MySQL 8.0. If you like installing MySQL and not MariaDB, you can do that as well. Now, after going through this tutorial, you can install MariaDB on Centos 8 and get started with it.