How to Install MariaDB on CentOS 8

MariaDB is a free and open-source database management system and acts as a drop replacement for the Oracle MySQL DB server. It is a community-driven and developed branch of Oracle MySQL server. MariaDB is a multi-user, multi-threaded SQL database server.
In this tutorial, we will explain how to install and secure MariaDB 10.4 on CentOS 8.

Installing MariaDB on CentOS 8

If you don’t have any critical services running in Production on the server, update the system before you begin installation of MariaDB 10.4 on CentOS 8.

# dnf -y upgrade

We now need to add the MariaDB yum repository for our CPU architecture. This guide will cover adding repository for a x86_64 CPU machine.

cat <> /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos8-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF

After adding Yum repository, you can proceed to install MariaDB 10.4 repository to CentOS 8 straight away.
[box type=”note” align=”” class=”” width=””]We need to disable the rhel-8-for-x86_64-appstream-rpms and AppStream repository temporarily on CentOS 8 respectively to allow yum to download packages from MariaDB mirror.[/box]

# dnf install -y boost-program-options
# dnf --disablerepo=AppStream install -y MariaDB-server MariaDB-client

[ads]
Once the installation is complete, start the MariaDB service and enable it to automatically start on boot by typing:

# systemctl enable --now mariadb

To verify that the MariaDB server is running, type:

# systemctl status mariadb

The output should show that the service is active and enabled:

# systemctl status mariadb
 mariadb.service - MariaDB 10.4.12 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Thu 2020-02-13 19:25:16 UTC; 8s ago
     Docs: man:mysqld(8)
......................................

Secure MariaDB Database Server

MariaDB server package comes with a script called mysql_secure_installation performs several security-related operations, and sets the root password.
Run the script by typing:

# mysql_secure_installation

You will be prompted to set a password for the MariaDB root user. Once you do that, the script will also ask you to remove the anonymous user, restrict root user access to the local machine, and remove the test database. You should answer “Y” (yes) to all questions.
That’s it! You have installed and secured MariaDB on your CentOS server, and you’re ready to use it.
[ads]

Access MariaDB

To connect to the MariaDB server through the terminal as the root account type:

# mysql -u root -p

Enter the root password when prompted, and you will be presented with the MariaDB shell, as shown below:

# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.4.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Conclusion

In this tutorial, we’ve shown you how to install and secure MariaDB on CentOS 8, and how to connect to the MariaDB server from the command line.
If you have any questions or feedback, feel free to leave a comment.

Leave a Comment