如何在 Debian 12 上安装 MySQL

Linux命令 Edge插件网 2年前 (2023-07-08) 1562次浏览 已收录 0个评论

MySQL是一种流行的开源关系数据库管理系统,是许多Web应用程序和服务的基本组件。请记住继续探索MySQL的广泛功能和特性,以最大限度地发挥其在项目中的潜力。

如何在 Debian 12 上安装 MySQL

在 Debian 12 书虫上安装 MySQL

第 1 步。在我们安装任何软件之前,通过在终端中运行以下命令来确保您的系统是最新的非常重要:apt

<span class="pln">sudo apt update
sudo apt install apt</span><span class="pun">-</span><span class="pln">transport</span><span class="pun">-</span><span class="pln">https lsb</span><span class="pun">-</span><span class="pln">release ca</span><span class="pun">-</span><span class="pln">certificates curl dirmngr gnupg</span>

此命令将刷新存储库,允许您安装最新版本的软件包。

第 2 步。在 Debian 12安装 MySQL

首先,通过添加 MySQL APT 配置文件来启用 MySQL 存储库。在终端中,执行以下命令下载并安装软件包:

<span class="pln">sudo apt install </span><span class="pun">-</span><span class="pln">y lsb</span><span class="pun">-</span><span class="pln">release wget
wget https</span><span class="pun">:</span><span class="com">//dev.mysql.com/get/mysql-apt-config_0.8.18-1_all.deb</span><span class="pln">
sudo dpkg </span><span class="pun">-</span><span class="pln">i mysql</span><span class="pun">-</span><span class="pln">apt</span><span class="pun">-</span><span class="pln">config_0</span><span class="pun">.</span><span class="lit">8.18</span><span class="pun">-</span><span class="lit">1</span><span class="pln">_all</span><span class="pun">.</span><span class="pln">deb</span>

在安装过程中,系统将提示您选择要安装的MySQL版本。选择所需的版本,然后选择“确定”继续。

启用 MySQL 存储库后,通过运行以下命令更新包列表并安装 MySQL 服务器和客户端包:

<span class="pln">sudo apt update
sudo apt install mysql</span><span class="pun">-</span><span class="pln">server mysql</span><span class="pun">-</span><span class="pln">client</span>

在安装过程中,系统将提示您为 MySQL 设置根密码。选择一个强密码并记住它以备将来使用。

第 3 步。配置 MySQL。

安装 MySQL 后,正确配置它以获得最佳性能和安全性至关重要。

A. 保护 MySQL 安装

保护您的 MySQL 安装对于保护您的数据免受未经授权的访问至关重要。要保护安装,请按照以下步骤在终端中执行以下命令以运行MySQL安全安装脚本:

<span class="pln">sudo mysql_secure_installation</span>

像这样配置它

<span class="pun">-</span> <span class="typ">Set</span><span class="pln"> root password</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> anonymous users</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Disallow</span><span class="pln"> root login remotely</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Remove</span><span class="pln"> test database </span><span class="kwd">and</span><span class="pln"> access to it</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y
</span><span class="pun">-</span> <span class="typ">Reload</span><span class="pln"> privilege tables now</span><span class="pun">?</span> <span class="pun">[</span><span class="pln">Y</span><span class="pun">/</span><span class="pln">n</span><span class="pun">]</span><span class="pln"> y</span>

一旦安装和配置完成,验证 MySQL 是否在您的 Debian 12 Bookworm 系统上正常运行至关重要。要检查 MySQL 服务的状态,请执行以下命令:

<span class="pln">sudo systemctl status mysql</span>

B. 调整 MySQL 配置

要优化 MySQL 性能并适应特定用例的要求,您可以调整 MySQL 配置设置。现在在具有root权限的文本编辑器中打开MySQL配置文件:

<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">/</span><span class="pln">mysql</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">mysqld</span><span class="pun">.</span><span class="pln">cnf</span>

第 4 步。创建数据库和用户的示例。

为了演示 MySQL 的功能,让我们使用命令行界面创建一个示例数据库和用户。现在打开一个终端并输入以下命令以访问 MySQL 命令行界面:

<span class="pln">mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>

要创建新数据库,请在 MySQL 命令行界面中执行以下命令:

<span class="pln">CREATE DATABASE mydatabase</span><span class="pun">;</span>

要创建具有特定权限的新 MySQL 用户,请使用以下命令:

<span class="pln">CREATE USER </span><span class="str">'myuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pun">;</span>

要授予新创建的用户对数据库的所有权限,请执行以下命令:

<span class="pln">GRANT ALL PRIVILEGES ON mydatabase</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'myuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span>

感谢您使用本教程在 Debian 11 书虫上安装最新版本的 MySQL 数据库。有关其他帮助或有用信息,我们建议您查看MySQL官方网站


Edge插件网 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:如何在 Debian 12 上安装 MySQL
喜欢 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址