Home » MariaDB: Install MariaDB on Linux – CentOS 7

MariaDB: Install MariaDB on Linux – CentOS 7

by Pring
MariaDB: Install MariaDB on Linux - CentOS 7

I. Introduction.

This tutorial will teaches you how to install MariaDB Linux – CentOS 7 server. If you specifically need MySQL, see the How to Install MySQL on CentOS 7 guide. If you’re wondering about MySQL vs. MariaDB, MariaDB is the preferred package and should work seamlessly in place of MySQL.

MariaDB is an open-source database management system, commonly installed as 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. 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.

Read other related posts:

II. Prerequisites.

1.  Login to your system via SSH. You can use PuTTy tool or Poderosa tool,…
2.  Login with root user.  If you are logged in as another user, you will need to add sudo before each command.

III. Install Python on CentOS 7 by step by step.

To install MySQL 8.0 on Linux – CentOS 7. Follow these steps:
Step 1. Install MariaDB.
Step 2. Securing the MariaDB Server.
Step 3. Testing the Installation.

You can see details of Video on How to Install Python on Linux – CentOS 7 as below.
[Sorry, the video we will update later]

Or you also can see details as below.

Step 1. Install MariaDB.

The first step is to Enable the MariaDB repository. Create a repository file named MariaDB.repo.

Enter command below:

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

Add the following content:

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Install MariaDB server package with yum command.

Enter command below. When install, Yum may prompt you to import the MariaDB GPG key. Type y and hit Enter.

sudo yum install mariadb-server

If installation fails, you must delete the MariaDB packages and delete all old installations. 
Read the following articles: Uninstall MariaDB on RHEL 7/CentOS 7

Enable MariaDB when boot your system. Use command below.

sudo systemctl enable mariadb

Start MariaDB Server.

sudo systemctl start mariadb

Step 2. Securing the MariaDB Server.

The next step is to run the mysql_secure_installation script. The script will prompt you to set up the root user password, remove the anonymous user, restrict root user access to the local machine, and remove the test database.
Enter command below:

sudo mysql_secure_installation

Sample Output:

[root@devopsio ~]# sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

Step 3. Testing the Installation.

To verify the installation check the MariaDB service status by typing:

sudo systemctl status mariadb

Sample Output:

[root@devopsio ~]# sudo systemctl status mariadb
● mariadb.service - MariaDB 10.1.41 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 Sat 2019-08-03 15:54:03 UTC; 3min 59s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 18904 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 18864 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
  Process: 18862 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 18876 (mysqld)
   Status: "Taking your SQL requests now..."
   CGroup: /system.slice/mariadb.service
           └─18876 /usr/sbin/mysqld

We also can verify our installation and get information about it by connecting with the mysqladmin tool, a client that lets you run administrative commands. Use the following command to connect to MariaDB as root (-u root), prompt for a password (-p), and return the version.

mysqladmin -u root -p version

Sample Output:

[root@devopsio ~]# mysqladmin -u root -p version
Enter password: 
mysqladmin  Ver 9.1 Distrib 10.1.41-MariaDB, for Linux on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Server version          10.1.41-MariaDB
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /var/lib/mysql/mysql.sock
Uptime:                 7 min 6 sec

Threads: 1  Questions: 16  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 12  Queries per second avg: 0.037

IV. Conclusion.

In this tutorial, we’ve installed MariaDB on CentOS 7 server. To learn more about using MariaDB, this guide to learning more about MariaDB.
You can now visit the official MariaDB Documentation page and learn how to get started with MariaDB.


Install MariaDB on Linux – CentOS 7 is complete. Wish you success and luck.
Thanks and best regards!
— Pring —

Related Articles

1 comment

bjvgrxhryn November 10, 2020 - 11:35 pm

Muchas gracias. ?Como puedo iniciar sesion?

Reply

Leave a Comment