For CentOS 7 users, MariaDB is the default database system as it replaced MySQL as the default database system.
The original MySQL developers designed MariaDB as a backward-compatible drop-in replacement for MySQL. This open-source database management system uses a relational database and structured query language (SQL).
In this tutorial you will learn how to install MariaDB on CentOS 7 from the local repository or official repository.
The article also shows you how to secure MariaDB and connect to the database management system from the command-line.
- An RHEL-based system, such as CentOS 7
- Access to a terminal/command-line
- The yum package manager, included by default
- Access to the root user or a user with sudo privileges
2 Options for Installing MariaDB on CentOS
There are two (2) options to install MariaDB on your CentOS system.
The first is with the CentOS local repository. However, this repository does not provide the newest version of MariaDB available.
The second option includes the latest stable version available but requires additional configuration steps.
Option 1: Install MariaDB 5.5 on CentOS 7 from Local Repository
The simplest way to install MariaDB is from the CentOS repository. Although the repository does not offer the latest stable version, MariaDB 5.5 is a stable release.
1. Open the terminal and type in the following command to download and install the MariaDB package:
yum install mariadb-server
Y to confirm installation and hit
2. To start using the MariaDB service and enable it to run on boot use the commands:
systemctl start mariadb
systemstl enable mariadb
3. Lastly, verify the installation by checking the service status with:
systemctl status mariadb
The output should tell you the service is
active (running), as in the example below:
Option 2: Install MariaDB 10.3 on CentOS 7 from MariaDB Repository
You can install the latest stable version of MySQL by downloading it from the official MariaDB repository.
1. First, you need to create a repository file for MariaDB (MariaDB.repo) using a text editor. Type in the following command:
This creates and opens a new file under the name MariaDB.repo in the /etc/yum.repos.d/ directory. At the moment, the file is still empty and it appears as in the following image:
2. Copy the following lines in the text editor:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.3/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
Note: Change the
baseurl line to correspond to your Linux distribution. For Example, if you are using RHEL instead of CentOS, type:
baseurl = http://yum.mariadb.org/10.1/rhel7-amd64
3. Once you have added the content to the repository file, save and close the text editor.
4. Next, install the latest MariaDB version with the command:
yum install mariadb-server mariadb-client -y
5. Finally, check whether the installation was successful by running the service and verifying the MariaDB version:
service mysql start
Note: Although MariaDB replaced MySQL, it still uses some commands to reference to it. For example:
This open-source database management system does not have secure settings by default. To ensure your data is safe, run its installation script to configure the security options.
1. Start by typing the following command to initiate running the security script:
2. Next, you will be presented with the following options:
- Set root password? [Y/n] – type y (for yes) and hit Enter create a root password for your database
- Remove anonymous users? [Y/n] – type y and hit Enter
- Disallow root login remotely? [Y/n] – type y and hit Enter
- Remove test database and access to it? [Y/n] – type y and hit Enter
- Reload privilege tables now? [Y/n] – type y and hit Enter
The output informs you that the MariaDB installation is now secure:
Read our article on How to Create a MariaDB User and Grant Privileges.
Connecting to MariaDB From Command Line
1. Connect to MariaDB from the command line as the root user with the command:
mysql -h localhost -u root -p
2. When prompted, type in the root password you have set in the previous step, while securing the MariaDB installation.
3. A welcome message will appear as follows:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is <strong>#your id number</strong> Server version: 10.3.15-MariaDB MariaDB Server Type <strong>'help;'</strong> or '<strong>\h</strong>' for help. Type '<strong>\c</strong>' to clear the current input statement.
4. Once you have finished working with the database, exit MariaDB with the following command:
Now you know how to install MariaDB on CentOS. We also covered securing MariaDB and connecting to the database management system from the command line.
Now that you have everything set up, you can start managing and storing data.