MariaDB 是一个开源关系数据库管理系统,向后兼容,是 MySQL 的二进制直接替代品。它是由 MySQL 的一些原始开发人员和社区中的许多人开发的。
在本教程中,我们将解释如何在 CentOS 8 上安装和保护 MariaDB 10.3。
在 CentOS 8 上安装 MariaDB#
在撰写本文时,CentOS 8 存储库中可用的 MariaDB 版本是 10.3。
以 root 身份运行以下命令或具有 sudo 权限的用户在 CentOS 8 上安装 MariaDB 10.3:
sudo dnf install @mariadb
The @mariadb
模块安装 MariaDB 服务器和所有依赖项。
安装完成后,启动 MariaDB 服务并使其在启动时自动启动,输入:
sudo systemctl enable --now mariadb
要验证 MariaDB 服务器是否正在运行,请键入:
sudo systemctl status mariadb
输出应显示该服务处于活动状态并已启用:
● mariadb.service - MariaDB 10.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2019-12-08 21:05:26 UTC; 15s ago
...
保护 MariaDB#
MariaDB 服务器包附带一个名为mysql_secure_installation
执行一些与安全相关的操作,并设置 root 密码。
通过键入以下内容运行脚本:
sudo mysql_secure_installation
系统将提示您为 MariaDB root 用户设置密码。执行此操作后,脚本还会要求您删除匿名用户、限制 root 用户对本地计算机的访问,并删除测试数据库。您应该对所有问题回答“Y”(是)。
就是这样!您已经在 CentOS 服务器上安装并保护了 MariaDB,并且可以使用它了。
连接到 MariaDB Shell#
要以 root 帐户类型通过终端连接到 MariaDB 服务器:
mysql -u root -p
输入根密码出现提示时,您将看到 MariaDB shell,如下所示:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.3.11-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)]>
结论#
在本教程中,我们向您展示了如何在 CentOS 8 上安装和保护 MariaDB,以及如何从命令行连接到 MariaDB 服务器。
现在您的 MariaDB 服务器已启动并正在运行,您可以连接到 MariaDB shell 并启动创建新的数据库和用户
.
CentOS 8还提供MySQL 8.0。如果您想安装 MySQL 而不是 MariaDB,请检查如何在 CentOS 8 上安装 MySQL指导。请注意,您不能在同一服务器上同时安装 MariaDB 和 MySQL。
如果您有任何问题或反馈,请随时发表评论。