在 CentOS 8 上安装 MariaDB
在本教程中,我们将说明如何在 CentOS 8 上安装和保护 MariaDB 10.3 。
MariaDB 是一个开放源代码关系数据库管理系统,向后兼容,替代了 MySQL 。它由 MySQL 的某些原始开发人员和社区中的许多人开发。
在 CentOS 8 上安装 MariaDB
在撰写本文时, CentOS 8 存储库中可用的 MariaDB 版本是 10.3 。
以超级用户或具有 sudo 特权的用户身份运行以下命令,以在 CentOS 8 上安装 MariaDB 10.3 :
sudo dnf install @mariadb
该 @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 用户对本地计算机的访问,并删除测试数据库。您应该对所有问题回答“是 ”( 是)。
现在,您已经在 CentOS 服务器上安装并保护了 MariaDB ,并准备使用它。
连接到 MariaDB Shell
要通过终端作为根帐户类型连接到 MariaDB 服务器,请执行以下操作:
mysql -u root -p
在出现提示时输入 root 密码,然后将为您提供 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 。