在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容

在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8

发表 admin at 2025年2月28日
类别
  • 未分类
标签

部署正确的数据库管理系统是您的业务成功指标之一。有大量 RDMS 可供选择,在某种程度上,选择正确的 RDMS 可能会令人困惑。 MariaDB 是一个开源且成功的项目,源自 MySQL 关系数据库管理系统。它得到了数百名贡献者的支持,其中大多数是严重依赖 MariaDB 来支持其业务运营的公司。 MariaDB 与 MySQL 保持高度兼容性,库二进制奇偶校验以及与 MySQL 精确匹配的 API 和命令。

在这个简短的教程中,我们将在 CentOS 8 上执行单节点、主、MariaDB 10.7 的安装 | Rocky Linux 8 Linux 系统。对于高度可用的部署,您可以探索 MariaDB Galera Cluster 项目。 MariaDB 10.7 具有以下新功能;

  • 新 UUID数据类型 – 有一种新的 UUID 数据类型,旨在存储 128 位 UUID(通用唯一标识符)数据。
  • InnoDB 更新 – MariaDB InnoDB 存储引擎的新改进和功能
  • 添加 提供商插件  – 有五个提供商插件(bzip2、lzma、lz4、lzo、 snappy)用于压缩功能。
  • 自然排序 – 用于按字母顺序对字符串进行排序
  • 新增 SFORMAT 功能
  • 密码重用 – password_reuse_check插件是一个新的密码验证插件
  • InnoDB 批量插入 – 批量插入、预排序和构建索引,一次一页
  • 诊断属性 – 用于识别受影响的行
  • 有关 MariaDB 10.7 中提供的新功能的更多详细信息,请查看 MariaDB 基金会发布公告页面。

在 CentOS 8 上安装 MariaDB 10.7 |洛基 Linux 8

现在我们已经介绍了 MariaDB 数据库的一些基础知识和 10.7 版本中的新功能,我们开始在 CentOS 8 上安装和配置 MariaDB 10.7 |洛基 Linux 8.

1)添加MariaDB YUM存储库

MariaDB 团队维护 YUM 和 APT 存储库,并在 MariaDB 服务器和客户端包上提供稳定且最新的版本。 MariaDB 服务器和客户端包也可在 AppStream 存储库中作为 CentOS 8 中的模块 |洛基 Linux 8 服务器。唯一需要注意的是版本。

$ sudo dnf module list mariadb
Last metadata expiration check: 1 day, 16:20:23 ago on Mon 22 Nov 2021 05:45:07 AM UTC.
Rocky Linux 8 - AppStream
Name                                       Stream                                      Profiles                                                      Summary
mariadb                                    10.3 [d]                                    client, galera, server [d]                                    MariaDB Module
mariadb                                    10.5                                        client, galera, server [d]                                    MariaDB Module

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

从输出中可以看出,系统存储库中只有 MariaDB 版本 10.5 和 10.3。

运行以下命令下载 MariaDB YUM 存储库设置脚本:

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

运行下载的脚本,同时传递相关选项来配置存储库。

sudo bash mariadb_repo_setup --mariadb-server-version=10.7

该脚本将自动配置repo文件并导入GPG包签名密钥

[info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
[info] Adding trusted package signing keys...
/etc/pki/rpm-gpg /home/rocky
/home/rocky
[info] Successfully added trusted package signing keys
[info] Cleaning package cache...
27 files removed

列出配置的存储库

$ sudo dnf repolist
repo id                                                                                        repo name
appstream                                                                                      Rocky Linux 8 - AppStream
baseos                                                                                         Rocky Linux 8 - BaseOS
extras                                                                                         Rocky Linux 8 - Extras
mariadb-main                                                                                   MariaDB Server
mariadb-maxscale                                                                               MariaDB MaxScale
mariadb-tools                                                                                  MariaDB Tools

2)在CentOS 8上安装MariaDB 10.7 |洛基 Linux 8

可以通过在终端中运行以下命令从 MariaDB 存储库安装 MariaDB 10.7 软件包

sudo dnf -y module reset mariadb
sudo dnf install MariaDB-server MariaDB-client MariaDB-backup

确认正在安装的 MariaDB 服务器和客户端软件包的版本,如果可以则继续。

Dependencies resolved.
======================================================================================================================================================================================================
 Package                                           Architecture                       Version                                                          Repository                                Size
======================================================================================================================================================================================================
Installing:
 MariaDB-backup                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                             7.0 M
 MariaDB-client                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              15 M
 MariaDB-server                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              25 M
Installing dependencies:
 MariaDB-common                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                              88 k
 MariaDB-shared                                    x86_64                             10.7.1-1.el8                                                     mariadb-main                             115 k
 boost-program-options                             x86_64                             1.66.0-10.el8                                                    appstream                                140 k
 galera-4                                          x86_64                             26.4.9-1.el8                                                     mariadb-main                              13 M
 libaio                                            x86_64                             0.3.112-1.el8                                                    baseos                                    31 k
 libpmem                                           x86_64                             1.6.1-1.el8                                                      appstream                                 78 k
 lsof                                              x86_64                             4.93.2-1.el8                                                     baseos                                   252 k
 perl-DBI                                          x86_64                             1.641-3.module+el8.4.0+509+59a8d9b3                              appstream                                739 k
 perl-Math-BigInt                                  noarch                             1:1.9998.11-7.el8                                                baseos                                   194 k
 perl-Math-Complex                                 noarch                             1.59-420.el8                                                     baseos                                   107 k
 socat                                             x86_64                             1.7.4.1-1.el8                                                    appstream                                322 k
Enabling module streams:
 perl-DBI                                                                             1.641

Transaction Summary
======================================================================================================================================================================================================
Install  14 Packages

Total download size: 62 M
Installed size: 288 M
Is this ok [y/N]: y

可以使用rpm命令检查有关软件包的详细信息:

$ sudo dnf info MariaDB-server
Last metadata expiration check: 0:02:30 ago on Tue 23 Nov 2021 10:13:33 PM UTC.
Installed Packages
Name         : MariaDB-server
Version      : 10.7.1
Release      : 1.el8
Architecture : x86_64
Size         : 119 M
Source       : MariaDB-server-10.7.1-1.el8.src.rpm
Repository   : @System
From repo    : mariadb-main
Summary      : MariaDB: a very fast and robust SQL database server
URL          : http://mariadb.org
License      : GPLv2
...

3)在CentOS 8上启动MariaDB 10.7服务器 |洛基 Linux 8

MariaDB服务器服务在安装后不会自动启动。你需要自己启动它

$ sudo systemctl enable --now mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

可以使用以下命令验证服务的状态:

$ systemctl status mariadb
● mariadb.service - MariaDB 10.7.1 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/mariadb.service.d
           └─migrated-from-my.cnf-settings.conf
   Active: active (running) since Tue 2021-11-23 22:17:40 UTC; 47s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 16703 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 16676 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSI>
  Process: 16674 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
 Main PID: 16687 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 16 (limit: 49496)
   Memory: 68.0M
   CGroup: /system.slice/mariadb.service
           └─16687 /usr/sbin/mariadbd
...

mariadb 客户端命令还可以打印服务器和客户端版本:

$ mariadb -V
mariadb  Ver 15.1 Distrib 10.7.1-MariaDB, for Linux (x86_64) using readline 5.1

4) 安全的 MariaDB 服务器安装

在默认安装下,MariaDB 数据库服务器不安全。 root用户无需密码即可访问shell,并且root用户可以从远程系统登录。这是一个安全缺陷,尤其是在生产环境设置中。

运行提供的脚本,通过交互式提示帮助您强化 MariaDB 服务器

$ sudo 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): <ENTER>
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] y
Enabled successfully!
Reloading privilege tables..
 ... Success!


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

Change the root password? [Y/n] y
New password: <INPUT-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 用户身份登录,则可能会失败并显示错误消息。

$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

使用密码访问即可

$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.7.1-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)]>

5)在MariaDB中创建测试数据库/用户

要创建数据库(假设为 testdb),请运行以下命令:

CREATE DATABASE testdb;

通过显示所有可用数据库来检查数据库是否已创建。

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| testdb             |
+--------------------+
5 rows in set (0.000 sec)

MariaDB 是其他商业数据库管理系统的一个很好的替代品。我们希望我们的指南能够帮助您在 CentOS 8 上安装 MariaDB 10.7 | Rocky Linux 8 服务器或台式机。您的持续支持让我们深感荣幸,祝您幸福!

良好的 Udemy 学习课程:
  • 终极 MySQL 训练营:从 SQL 初学者到专家
  • 学习 MySQL 数据库设计
  • SQL – 用于数据分析和商业智能的 MySQL
  • SQL 初学者:使用 MySQL 和数据库设计学习 SQL
  • MySQL、SQL 和存储过程(从初级到高级)
  • 完整的 MySQL 开发人员课程
  • MySQL 数据库管理:初级 SQL 数据库设计
©2015-2025 Norria support@alaica.com