MariaDB是一个流行的开源关系数据库系统,由MySQL服务器的原始开发人员开发。它最初是从 MySQL 服务器分叉出来的,并进行了多项增强。
本教程将指导您在 Ubuntu 22.04 Linux 系统上安装 MariaDB 服务器。
1.配置存储库
MariaDB 软件包可在默认 Ubuntu 存储库中找到。此外,MariaDB 还提供了一个官方存储库来在 Ubuntu 系统上安装最新版本。
为了配置 MariaDB Apt 存储库,请使用 sudo 特权帐户打开终端并运行以下命令。
sudo apt install software-properties-common dirmngr apt-transport-https
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://atl.mirrors.knownhost.com/mariadb/repo/10.8/ubuntu jammy main'
上述命令将在下创建一个存储库文件/etc/apt/sources.list.d 目录。
2.在Ubuntu上安装MariaDB
接下来,执行以下命令在 Ubuntu 系统上安装 MariaDB 服务器和客户端。
sudo apt update
sudo apt install mariadb-server
当提示确认时,按“y”并按 Enter 键。
Installing MariaDB Server on Ubuntu 安装完成后,执行mysql_secure_installation
脚本来保护 MariaDB 服务器并为 root 帐户设置密码。
sudo sudo mysql_secure_installation
按照屏幕上的说明完成安全向导。
3.管理MariaDB服务
MariaDB 创建一个 systemd 配置文件来管理其服务。使用以下命令停止、启动或重新启动 MariaDB 服务。
sudo systemctl start mariadb
sudo systemctl stop mariadb
要查看 MariaDB 服务的当前状态,请键入:
sudo systemctl status mariadb
4.连接到MariaDB
您可以获得 MariaDB shell 来创建用户、数据库和其他相关活动。要连接 shell,请键入:
mysql -u root -p
输入您使用以下命令设置的 MariaDB root 用户密码mysql_secure_installation
命令。
Output:
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 10.8.3-MariaDB-2ubuntu1 Ubuntu 22.04
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)]>
结论
本教程帮助您在 Ubuntu 系统上安装和配置 MariaDB 服务器。现在你可以创建数据库 为您带来精彩的应用程序。我们强烈推荐创建单独的用户帐户 对于数据库。