How to install MariaDB Database Server on CentOS 8

Автор George, Март 30, 2023, 01:52

« назад - далее »

George

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.

#
Код: bash
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.

#
Код: bash
vi /etc/yum.repos.d/MariaDB.repo
Add following directives in this file.

Код: bash
# 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.

#
Код: bash
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.

#
Код: bash
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.

#
Код: bash
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.

#
Код: bash
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.

#
Код: bash
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.
  •  

🡱 🡳

Отметьте интересные вам фрагменты текста и они станут доступны по уникальной ссылке в адресной строке браузера.