在 CentOS 8|RHEL 8|Rocky Linux 8 上安装 MariaDB
本指南旨在帮助您在以下位置安装 MariaDB 数据库服务器:
MariaDB 是社区开发的 MySQL 关系数据库管理系统的分支。它是一个快速而强大的数据库服务器,其开发和改进背后有一个庞大的社区。
对于 MariaDB 10.6 的安装,请查看:如何在 CentOS 8/RHEL 8 上安装 MariaDB 10.6
RHEL 8 中提供的 MariaDB 10.x 提供了超过 RHEL 7 中提供的 5.5 的许多新功能。其中一些新更改包括:
- 使用 InnoDB 作为默认存储引擎,而不是 XtraDB。
- 系统版本表
- FOR 循环
- MariaDB Galera Cluster 是一个同步多主集群,现已成为 MariaDB 的标准部分。
- 序列
- InnoDB 的即时添加列
- 隐形柱
- 并行复制
- 多源复制
- 常用表表达式
- 存储引擎独立的列压缩
安装 MariaDB CentOS 8|RHEL 8|Rocky Linux 8
请按照以下步骤安装和配置 MariaDB 10.x
第 1 步:更新您的 CentOS 8|RHEL 8|Rocky Linux 8 系统
更新基于 RHEL 8 的系统:
sudo dnf -y update
步骤 2:在 CentOS 8|RHEL 8|Rocky Linux 8 上安装 MariaDB
mariadb
软件包可在 AppStream 存储库中找到,可以通过运行以下命令进行安装:
sudo dnf module install mariadb
使用y确认安装
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.28
Release : 1.module_el8.3.0+757+d382997d
Architecture: x86_64
Install Date: Wed 16 Aug 2023 11:02:38 AM UTC
Group : Unspecified
Size : 85965773
License : GPLv2 with exceptions and LGPLv2 and BSD
Signature : RSA/SHA256, Mon 19 Apr 2021 08:37:42 PM UTC, Key ID 05b555b38483c65d
Source RPM : mariadb-10.3.28-1.module_el8.3.0+757+d382997d.src.rpm
Build Date : Mon 19 Apr 2021 04:19:39 PM UTC
Build Host : x86-01.mbox.centos.org
Relocations : (not relocatable)
Packager : CentOS Buildsys <[email >
Vendor : CentOS
URL : http://mariadb.org
Summary : The MariaDB server and related files
....
第 3 步:配置 MariaDB CentOS 8|RHEL 8|Rocky Linux 8
使用以下命令激活 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.28-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)]> SELECT VERSION();
+-----------------+
| VERSION() |
+-----------------+
| 10.3.28-MariaDB |
+-----------------+
1 row in set (0.000 sec)
您现在已经安装了 MariaDB 数据库服务器
如果您更喜欢从 Web 界面管理 MariaDB 数据库服务器,请查看我们的指南,了解如何在 RHEL 8 上安装和配置 phpMyAdmin。
推荐书籍:
- MySQL 数据库管理书籍
其他指南:
- 如何在 RHEL 8 上使用 mod_ssl 和 mod_http2 安装 Apache
- 如何在 RHEL 8 上安装 PHP 7.3、PHP 7.3-FPM
- 如何在 RHEL 8 上安装 PHP 7.2
- 如何在 RHEL 8 上安装 Python 3/Python 2.7
- 在 RHEL 8 上安装 Docker 和 Docker Compose