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. MariaDB is part of the popular LEMP (Linux, Nginx, MySQL/MariaDB, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data.
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.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related MariaDB queries.
In this context, we shall look into how to install MariaDB on CentOS 7 server.
Before performing this Installation procedure, ensure that you are logged in to a CentOS server with a non-root user with sudo privileges.
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.
To begin, 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:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.3/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
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 <package-signing-key@mariadb.org>"
Fingerprint: 1993 69e5 404b d5fc 7d2f e43b cbcb 082a 1bb9 43db
From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Press 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)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf
Active: active (running) since Tue 2019-04-20 07:36:46 IST; 22s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
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:
$ sudo mysql_secure_installation
At first, it will prompt you to enter root user password.
Next, it will ask you if 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.
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:
Output
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.
MariaDB [(none)]>
This article covers how to install and Secure MariaDB on a CentOS 7 server. MariaDB is a fork of MySQL managed by the original MySQL developers. It's designed as a replacement for MySQL, uses some commands that reference mysql, and is the default package on CentOS 7.
To Install MariaDB 5.5 on CentOS 7:
1. Install the MariaDB package using the yum package manager:
$ sudo yum install mariadb-server
2. Once the installation is complete, start the MariaDB service and enable it to start on boot using the following commands:
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
To install MariaDB on CentOS 8:
1. Open the terminal application. Another option is to log in using the ssh command:
ssh user@centos-8-server-ip
2. Install the MariaDB on CentOS 8 by running the command:
$ sudo yum install mariadb-server
3. Secure the MariaDB server in CentOS 8 by running the command:
$ sudo mysql_secure_installation
4. Finally test MariaDB installation by running the command:
$ mysql -u root -p
MariaDB vs MySQL:
Even though MariaDB is a fork of MySQL, these two database management systems are still quite different:
MariaDB is fully GPL licensed while MySQL takes a dual-license approach.
MariaDB supports a lot of different storage engines.
In many scenarios, MariaDB offers improved performance.