How to Install MariaDB on CentOS 7

Introduction

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.

header for a tutorial on installing mariadb on centOS 7

Prerequisites

  1. An RHEL-based system, such as CentOS 7
  2. Access to a terminal/command-line
  3. The yum package manager, included by default
  4. 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

Press Y to confirm installation and hit Enter.

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:

check mariadb status

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:

vi /etc/yum.repos.d/MariaDB.repo

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:

mariadb repo file

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
repo file for mariadb

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
mysqld -V
check mariadb version

Note: Although MariaDB replaced MySQL, it still uses some commands to reference to it. For example: mysql -V.

Securing MariaDB

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:

mysql_secure_installation

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:

securing mariadb

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 #your id number
Server version: 10.3.15-MariaDB MariaDB Server
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

4. Once you have finished working with the database, exit MariaDB with the following command:

mysql> exit

Conclusion

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.

原创文章,作者:carmelaweatherly,如若转载,请注明出处:https://blog.ytso.com/224028.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论