MariaDB is an open-source database management system and backward compatible replacement of MySQL. MariaDB is a fork of MySQL and managed by the original MySQL developers. This guide outlines how to install MariaDB on CentOS 7 server.
If you have requirement to install MySQL on your server, check the How to Install MySQL on CentOS 7 tutorial. MariaDB is available by default with CentOS 7 system.
Ensure that you are logged in to a CentOS server with a non-root user with sudo privileges.
Install MariaDB on CentOS 7
With the release of CentOS 7, MySQL was replaced with MariaDB as the default database system. MariaDB 5.5 version is provided in default CentOS repositories but it’s not latest version and have no longer support. So we are going to install MariaDB 10.3 version. Follow the below steps to install MariaDB server 10.3 on CentOS 7:
First of all, we need to enable the MariaDB repository. So create a file
/etc/yum.repos.d/MariaDB.repo using below command:
sudo nano /etc/yum.repos.d/MariaDB.repo
Now add the following lines to that file:
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
Now install MariaDB server and MariaDB client packages on CentOS 7 using
yum same as other packages we are installing.
sudo yum install MariaDB-server MariaDB-client
It may prompt you to import the MariaDB GPG key:
Retrieving key from https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Importing GPG key 0x1BB943DB: Userid : "MariaDB Package Signing Key <email@example.com>" Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
y and hit
Enter to continue.
Once the installation is complete, you can start MariaDB service by below command:
sudo systemctl start mariadb
To verify the installation check the MariaDB service status by typing:
sudo systemctl status mariadb
It should show output as below:
● mariadb.service - MariaDB 10.3.14 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2019-04-20 07:36:46 IST; 22s ago
You can enable MariaDB to start on boot by run below command:
sudo systemctl enable mariadb
You can increase the security of MariaDB by removing anonymous user, restrict remote root access and remove test databases. For that run default security script by typing:
At first, it will prompt you to enter root user password. Next, it will ask you weather you want to change or set password for root. Press
y and hit
Enter key. After that it will prompt series of questions, Press
y and hit
Enter to accept the defaults for all the subsequent questions.
It will remove anonymous users, test databases, disable remote root logins and load these new rules so that MariaDB immediately respects the changes you have made.
Connect to MariaDB from the command line
If you have not installed phpMyAdmin then you can also connect MariaDB server through the terminal as the root account by typing:
mysql -u root -p
It will prompt you to enter root user password. Enter root user password which you set at previous step. Once you will logged in successfully it will show output as below:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.14-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.
In this guide, we’ve installed and secured MariaDB on a CentOS 7 server. If you have any questions, you can write down at comment box.