更多: zhilu jiaocheng

在 CentOS 8 上安装 MariaDB Server 10.5

我们添加了 MariaDB yum 存储库,现在我们可以使用 dnf 命令轻松安装 MariaDB 服务器。

[root@mariadb-01 ~]# dnf install -y MariaDB-server

创建了两个所有特权帐户。

一是root@localhost,它没有密码,但您需要是系统“root”用户才能连接。例如,使用sudo mysql,

第二个是mysql@localhost,它也没有密码,但您需要是系统“mysql”用户才能连接。
连接后,如果您需要能够使用密码而不使用sudo作为这些用户中的任何一个进行连接,则可以设置密码:

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

启用并启动 MariaDB 服务。

[root@mariadb-01 ~]# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service -> /usr/lib/systemd/system/mariadb.service.

验证 MariaDB 服务的状态。

[root@mariadb-01 ~]# systemctl status mariadb.service

如安装输出中所述,

  • Linux root用户无需任何密码即可以MariaDB root用户身份连接到MariaDB服务器
  • Linux mysql 用户无需任何密码即可以 MariaDB mysql 用户身份连接到 MariaDB 服务器

也不允许其他 Linux 用户以 MariaDB root 或者 mysql 用户身份登录。

要允许其他 Linux 用户以 root 或者 mysql 用户身份登录,我们需要为这些数据库用户设置密码。

使用新的 mariadb 命令连接 MariaDB 服务器。

[root@mariadb-01 ~]# 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)]>

为 root 和 mysql 用户设置强密码。

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

重新加载权限表。

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

列出 MariaDB 服务器中的可用数据库。

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

从 MariaDB Shell 退出。

MariaDB [(none)]> exit
Bye

我们的 MariaDB Server 10.5 已成功安装。

在 CentOS 8 上安装 MariaDB Server 10.5

在本文中,我们将学习如何在 CentOS 8 上安装 MariaDB Server 10.5 并配置管理员用户和数据库安全。

为 MariaDB 服务器配置数据库安全

我们可以选择删除测试数据库并限制 root 用户的远程登录。

为此,我们可以使用新的 mariadb-secure-installation 命令。

[root@mariadb-01 ~]# 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!

我们已经在 CentOS 8 上成功安装并配置了 MariaDB Server 10.5.

什么是 MariaDB 服务器?

MariaDB 是一个免费的开源 RDBMS(关系数据库管理系统)。

MariaDB 是 MySQL 数据库的一个分支,由 MySQL 项目的一些原始开发人员维护。

MariaDB 服务器具有高度可扩展性,可用作独立或者基于 Galera 的 MariaDB 集群环境。

在 CentOS 8 中安装 MariaDB Yum 存储库

MariaDB Server 10.5.3 是最新版本,因此它在 CentOS 8 yum 存储库中不可用。

MariaDB 提供了一个官方 yum 存储库,我们可以使用它在 CentOS 8 上安装 MariaDB Server 10.5.

创建一个 yum 存储库文件,如下所示。

[root@mariadb-01 ~]# vi /etc/yum.repos.d/MariaDB.repo

在此文件中添加以下指令。

# 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

为 MariaDB yum 存储库构建缓存。

[root@mariadb-01 ~]# 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.
日期:2020-09-17 00:11:35 来源:oir作者:oir