Latest

Sunday, 31 May 2020

How to install MariaDB Server 10.5 on CentOS 8

Install MariaDB Server 10.5 on CentOS 8

In this article, you will learn how to install MariaDB Server 10.5 on CentOS 8 and configure admin users and database security.

 

This Article Provides:

 

What is MariaDB Server? :

MariaDB is a free and open source RDBMS (Relational Database Management System). MariaDB is a fork of MySQL database maintained by some of the original developers of MySQL project. Just like its predecessor, MariaDB is mostly used as a backend database for PHP based servers. MariaDB is also used by many FOSS (Free and Open Source Software) utilities as their data repository.

MariaDB Server is highly scalable and can be used as Stand Alone or Galera based MariaDB Cluster environments.

MariaDB Server 10.5.3 is released on 12-May-2020 with many new features and some major changes. It is the latest release at the time of this writing.

Install MariaDB Server 10.5 on CentOS 8

New Features in MariaDB Server 10.5:

Some of the changes and features in MariaDB Server 10.5 are:

  • All binaries previously beginning with mysql now begin with mariadb, with symlinks for the corresponding mysql command
  • S3 Storage Engine - to archive MariaDB tables in Amazon S3, or any third-party public or private cloud that implements S3 API
  • Both S3 tables and partitioned S3 tables are discoverable. This means that if you create a partitioned S3 table, both the partitioned table and its partitions can be directly used by another server that has access to the S3 storage
  • New privileges were added by splitting the SUPER privilege, so that more fine grained tuning of what each user can do can be applied
  • Speed up binary row logging code
  • Improve connect speed (up to 25%)

You can see the complete list of new features in MariaDB 10.5.3 at MariaDB Official website.

 

Update CentOS 8 Software Packages:

Connect to mariadb-01.centlinux.com as root user by using a ssh tool.

It is a best practice to always update the Linux software packages before installing anything new.

# dnf update -y
Last metadata expiration check: 0:02:32 ago on Fri 29 May 2020 01:43:09 PM PKT.
Dependencies resolved.
Nothing to do.
Complete!

Our Linux machine is already up-to-date.

 

Install MariaDB Yum Repository in CentOS 8:

MariaDB Server 10.5.3 is the latest release therefore it is not available in CentOS 8 yum repositories.

MariaDB provides an official yum repository, that we can use to install MariaDB Server 10.5 on CentOS 8.

Create a yum repository file as follows.

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

Add following directives in this file.

# MariaDB 10.5 CentOS repository list - created 2020-05-29 08:37 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Build cache for MariaDB yum repository.

# dnf makecache
CentOS-8 - AppStream                            7.8 kB/s | 4.3 kB     00:00
CentOS-8 - Base                                 292  B/s | 3.9 kB     00:13
CentOS-8 - Extras                               3.7 kB/s | 1.5 kB     00:00
MariaDB                                         164 kB/s | 512 kB     00:03
Metadata cache created.

 

Install MariaDB Server 10.5 on CentOS 8:

We have added the MariaDB yum repository, now we can easily install MariaDB Server using dnf command.

# dnf install -y MariaDB-server
...
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at https://mariadb.com/kb or the
MySQL manual for more instructions.

Please report any problems at https://mariadb.org/jira

The latest information about MariaDB is available at https://mariadb.org/.
You can find additional information about the MySQL part at:
https://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
...
  MariaDB-shared-10.5.3-1.el8.x86_64
  galera-4-26.4.4-1.rhel8.0.el8.x86_64

Complete!

Enable and start MariaDB service.

# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service â /usr/lib/systemd/system/mariadb.service.

Verify the status for MariaDB service.

# systemctl status mariadb.service
â mariadb.service - MariaDB 10.5.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
  Drop-In: /etc/systemd/system/mariadb.service.d
           ââmigrated-from-my.cnf-settings.conf
   Active: active (running) since Fri 2020-05-29 13:59:04 PKT; 12s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 12496 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_ST>
  Process: 12475 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && V>
  Process: 12473 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STA>
 Main PID: 12485 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 11 (limit: 5916)
   Memory: 75.8M
   CGroup: /system.slice/mariadb.service
           ââ12485 /usr/sbin/mysqld

May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>

As mentioned in the installation output,

  • Linux root user can connect to MariaDB server as MariaDB root user without any password
  • Linux mysql user can connect to MariaDB server as MariaDB mysql user without any password

Also no other Linux user is allowed to login as MariaDB root or mysql users.

To allow the other Linux users to login as root or mysql user we need to set the password for these database users.

Connect with MariaDB server by using new mariadb command.

# mariadb -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.5.3-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)]>

Set strong passwords for root and mysql users.

MariaDB [(none)]> alter user 'root'@'localhost' identified by 'Ahmer@1234';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> alter user 'mysql'@'localhost' identified by 'Ahmer@1234';
Query OK, 0 rows affected (0.001 sec)

Reload the privileges tables.

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

List available databases in MariaDB server.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.001 sec)

Exit from MariaDB Shell.

MariaDB [(none)]> exit
Bye

Our MariaDB Server 10.5 has been installed successfully.

 

Configure Database Security for MariaDB Server:

We can optionally remove the test databases and restrict the remote logins by root user.

For this purpose, we can use new mariadb-secure-installation command.

# mariadb-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
haven't set the root password yet, you should just press enter here.

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

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

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] n
 ... skipping.

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!

We have successfully installed and configured MariaDB Server 10.5 on CentOS 8.

If you find this article useful? Don't you mind support us by Buy Me A Coffee


No comments:

Post a Comment

© 2022 CentLinux. All Rights Reserved.