如何在CentOS 8/RHEL 8上安装MariaDB服务器

时间:2020-02-23 14:30:46  来源:igfitidea点击:

本指南旨在在RHEL 8/CentOS 8上安装MariaDB数据库服务器。CentOS 8随MariaDB 10.3发行,后者与MySQL二进制兼容。 MariaDB 10.3是一个多用户,多线程的SQL数据库服务器。我们可以在我以前的文章Red Hat Enterprise Linux 8(RHEL 8)的新功能和评论中找到所有RHEL 8的新功能。

MariaDB是社区开发的MySQL关系数据库管理系统的分支。它是一种快速而强大的数据库服务器,在其开发和改进方面拥有庞大的社区。

RHEL8中的MariaDB 10.3与RHEL 7中分发的5.5

RHEL 8中提供的MariaDB 10.3提供了超过RHEL 7中提供的5.5以上的许多新功能。一些新更改包括:InnoDB用作默认存储引擎而不是XtraDB。系统版本的表FOR循环MariaDB Galera Cluster,一个同步多主集群,现在是MariaDB的标准部分.InnoDB的SequencesInstant ADD COLUMN可见列并行复制多源复制公用表表达式存储引擎独立的列压缩

在CentOS 8/RHEL 8上安装MariaDB 10.3

请按照以下步骤在RHEL 8/CentOS 8上安装和配置MariaDB 10.3.

步骤1:更新RHEL 8系统

sudo dnf -y update

步骤2:安装MariaDB数据库服务器

" mariadb"软件包可在AppStream存储库中找到,并可以通过运行以下命令进行安装:

sudo dnf module install mariadb

确认使用安装

Transaction Summary
=======================================================================================================================================================
Install  13 Packages

Total download size: 32 M
Installed size: 164 M
Is this ok [y/N]: y

确认已安装的MariaDB版本

$rpm -qi mariadb-server
Name        : mariadb-server
Epoch       : 3
Version     : 10.3.10
Release     : 2.el8+2039+dffd8723
Architecture: x86_64
Install Date: Sat 01 Dec 2016 04:31:39 AM EST
Group       : Unspecified
Size        : 87570890
License     : GPLv2 with exceptions and LGPLv2 and BSD.
Signature   : RSA/SHA256, Mon 15 Oct 2016 05:22:06 AM EDT, Key ID 199e2f91fd431d51
Source RPM  : mariadb-10.3.10-2.el8+2039+dffd8723.src.rpm
Build Date  : Fri 12 Oct 2016 09:48:53 AM EDT
Build Host  : x86-vm-05.build.eng.bos.redhat.com
Relocations : (not relocatable)
Packager    : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>
Vendor      : Red Hat, Inc.
URL         : http://mariadb.org
Summary     : The MariaDB server and related files
Description :
MariaDB is a multi-user, multi-threaded SQL database server. It is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MariaDB server and some accompanying files and directories.
MariaDB is a community developed branch of MySQL.

步骤3:在CentOS 8/RHEL 8上启动和配置MariaDB

使用以下命令激活mariadb服务:

sudo systemctl enable --now mariadb

服务启动后,运行命令mysql_secure_installation加强MariaDB数据库服务器的安全性。

$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: <ENTER NEW PASSWORD>
Re-enter new password: <CONFIRM 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!

确保我们:设置数据库root用户密码删除匿名用户禁止root用户远程登录删除测试数据库并对其进行访问

完成后,使用root用户测试访问权限

$mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 16
Server version: 10.3.10-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SELECT VERSION();
+-----------------+
| VERSION()       |
+-----------------+
| 10.3.10-MariaDB |
+-----------------+
1 row in set (0.001 sec)

现在,我们已在RHEL 8上安装了MariaDB数据库服务器。请保持连接状态,以在RHEL 8上进行更多MariaDB数据库服务器配置。

如果我们希望通过Web界面管理MariaDB数据库服务器,请查看我们的指南:了解如何在RHEL 8上安装和配置phpMyAdmin。