在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 | 操作系统在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 | 操作系统在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 | 操作系统在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 | 操作系统
  • 业务
  • 目标
  • 支持
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

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

在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 | 操作系统

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

在本文中,我们将了解如何在 CentOS 8 上安装 MariaDB 10.5 | CentOS 7 Linux 机器。 MariaDB 是 MySQL 关系数据库管理系统的社区分支,拥有巨大的社区支持。 MariaDB 10.5 稳定版于 2020 年 6 月发布,支持至 2025 年 6 月。您可以从变更页面看到 MariaDB 10.5 中的所有新功能。该软件可以在 GNU 通用公共许可证版本 2 的条件下免费使用。

如果您要从其他版本(例如 10.4)进行升级,请查看官方升级指南并注意两个版本的 MariaDB 之间的差异。这对于使用自定义变量来调整数据库并确保事务效率的生产用例非常重要。

在 CentOS 8 上安装 MariaDB 10.5 |操作系统7

MariaDB 团队为不同版本的 Linux 提供了维护的存储库以及最新的软件包。对于 CentOS,我们将使用 YUM 存储库。

第1步:添加MariaDB YUM存储库

运行以下命令将 MariaDB 提供的存储库添加到 CentOS 服务器。

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.5

通过更新缓存来确认存储库正在工作。

sudo yum makecache -y

列出可用的存储库:

$ sudo yum repolist
repo id                                                                        repo name
appstream                                                                      CentOS Stream 8 - AppStream
baseos                                                                         CentOS Stream 8 - BaseOS
epel                                                                           Extra Packages for Enterprise Linux 8 - x86_64
extras                                                                         CentOS Stream 8 - Extras
extras-common                                                                  CentOS Stream 8 - Extras common packages
mariadb-main                                                                   MariaDB Server
mariadb-maxscale                                                               MariaDB MaxScale
mariadb-tools                                                                  MariaDB Tools
remi                                                                           Remi's RPM repository for Enterprise Linux 8 - x86_64
remi-modular                                                                   Remi's Modular repository for Enterprise Linux 8 - x86_64
remi-safe                                                                      Safe Remi's RPM repository for Enterprise Linux 8 - x86_64

步骤2:在CentOS 8上安装MariaDB 10.5 |操作系统7

添加存储库并确认其正常工作后,我们可以继续在 CentOS 8/CentOS 7 Linux 计算机上安装 MariaDB 10.5。

CentOS 8:

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

CentOS 7:

sudo yum install MariaDB-server MariaDB-client MariaDB-backup

您可以检查要安装的软件包列表,如果同意则同意。

.....
Transaction Summary
================================================================================================================================================================
Install  54 Packages

Total download size: 67 M
Installed size: 298 M
Is this ok [y/N]: y

出现提示时还同意导入 GPG 密钥。

.....
Importing GPG key 0x1BB943DB:
 Userid     : "MariaDB Package Signing Key <[email >"
 Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB
 From       : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
Is this ok [y/N]: y

RPM 包详细信息:

$ rpm -qi  MariaDB-server
Name        : MariaDB-server
Version     : 10.5.19
Release     : 1.el8
Architecture: x86_64
Install Date: Wed 03 May 2023 09:30:59 AM UTC
Group       : Applications/Databases
Size        : 132031416
License     : GPLv2
Signature   : RSA/SHA512, Thu 02 Feb 2023 11:10:09 PM UTC, Key ID f1656f24c74cd1d8
Source RPM  : MariaDB-server-10.5.19-1.el8.src.rpm
Build Date  : Mon 30 Jan 2023 10:19:47 PM UTC
Build Host  : rhel8-amd64
Relocations : (not relocatable)
Vendor      : MariaDB Foundation
URL         : http://mariadb.org
Summary     : MariaDB database server binaries
...

步骤3:在CentOS 8上启动MariaDB服务|操作系统7

CentOS 8和CentOS 7都使用Systemd init系统。我们可以使用 systemctl 命令启动服务,如下所示。

sudo systemctl start mariadb

要使该服务能够在服务器重新启动时启动,请使用以下命令:

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

使用 systemctl status 命令检查服务状态:

$ systemctl status mariadb
● mariadb.service - MariaDB 10.5.4 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 Sun 2020-06-28 19:34:56 CEST; 1min 35s ago
     Docs: man:mariadbd(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 4328 (mariadbd)
   Status: "Taking your SQL requests now..."
    Tasks: 9 (limit: 24392)
   Memory: 67.7M
   CGroup: /system.slice/mariadb.service
           └─4328 /usr/sbin/mariadbd

Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Plugin 'FEEDBACK' is disabled.
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] InnoDB: Buffer pool(s) load completed at 200628 19:34:56
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Server socket created on IP: '::'.
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Reading of all Master_info entries succeeded
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] Added new Master_info '' to hash table
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: 2020-06-28 19:34:56 0 [Note] /usr/sbin/mariadbd: ready for connections.
Jun 28 19:34:56 centos.computingforgeeks.com mariadbd[4328]: Version: '10.5.4-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server
Jun 28 19:34:56 centos.computingforgeeks.com systemd[1]: Started MariaDB 10.5.4 database server.
...

如果需要网络中的其他系统访问数据库服务器允许端口3306:

sudo firewall-cmd --add-service=mysql --permanent
sudo firewall-cmd --reload

为了使远程连接正常工作,服务应该侦听 IP 地址而不是本地主机环回接口。

# Listen on specific IP address in the server
bind-address=172.21.200.12

# Listen on all available interfaces
bind-address=0.0.0.0

步骤 4:在 CentOS 8 上保护 MariaDB 数据库 |操作系统7

提供了一个用于强化 MariaDB 数据库服务器的脚本。该脚本可以帮助您:

  • 设置root密码
  • 删除匿名数据库用户
  • 禁止以 root 用户身份远程登录数据库
  • 删除测试数据库

要启动数据库强化过程,请运行以下命令。

$ 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): 
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: 
Re-enter new 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 <ENTER>

您应该收到访问被拒绝错误:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

现在尝试以 root 用户身份并提供密码:

$ mysql -u root -p
Enter password: <ENTER-PASSWORD>
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.5.4-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.5.4-MariaDB |
+----------------+
1 row in set (0.001 sec)

MariaDB [(none)]> QUIT
Bye

您的数据库服务器现已可供使用。您可能需要的唯一附加设置是根据您的应用程序要求和用例将其调整为最佳性能。这超出了本指南的范围。

©2015-2025 Norria support@norria.com