本指南提供了有关如何在 Debian 11 上安装 MySQL 8 的分步教程。 MySQL 是一种快速、稳定且真正的多用户、多线程 SQL 数据库服务器,其主要目标是速度、稳健性和易用性。要查看 MySQL 8 提供的功能的全面描述,请导航到 MySQL 8 参考手册。
在 Debian 11 上安装 MySQL 8
Debian 11 未在其默认存储库中随附 MySQL 8。
apt show mysql-server
Package: mysql-server
State: not a real package (virtual)
N: Can't select candidate version from package mysql-server as it has no candidate
N: Can't select versions from package 'mysql-server' as it is purely virtual
N: No packages found
在 Debian 11 上安装 MySQL APT 存储库
在 Debian 11 上安装 MySQL 8 的推荐方法是通过 MySQL APT 存储库。
因此,您需要在 Debian 11 上安装 MySQL APT 存储库。这使得 MySQL 8 的安装成为一项无缝任务。
下载 MySQL 8 APT 存储库安装程序;
wget https://repo.mysql.com//mysql-apt-config_0.8.18-1_all.deb
安装 MySQL APT 仓库;
apt install ./mysql-apt-config_0.8.18-1_all.deb -y
请注意,在撰写本文时,Debian 11 牛眼不支持该存储库。
如果出现提示,请选择debian buster的存储库并按TAB键选择 Ok。按 ENTER 继续。
接下来,在 MySQL 产品上,选择Ok,然后按TAB键选择 Ok。按 ENTER 继续安装存储库。
如果再次提示选择产品,请按上述操作并按ENTER 完成MySQL APT 存储库的安装。
运行系统更新
在继续之前,请更新和升级您的系统包。
apt update
接下来,通过执行以下命令在 Debian 11 上安装 MySQL 8;
apt install mysql-server
该命令安装 MySQL 8 和所有必需的包依赖项。
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins
mysql-community-server mysql-community-server-core psmisc
The following NEW packages will be installed:
libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-client mysql-common mysql-community-client mysql-community-client-core mysql-community-client-plugins
mysql-community-server mysql-community-server-core mysql-server psmisc
0 upgraded, 14 newly installed, 0 to remove and 0 not upgraded.
Need to get 33.4 MB of archives.
After this operation, 282 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
...
安装过程中会提示你设置MySQL 8 root密码;
设置 MySQL 8 默认身份验证插件。
在Debian 11 上运行MySQL8
安装后,MySQL 8 将启动并允许在系统启动时运行;
systemctl status mysql
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-08-21 11:10:46 EAT; 30s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2193 ExecStartPre=/usr/share/mysql-8.0/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 2228 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 1133)
Memory: 356.8M
CPU: 1.388s
CGroup: /system.slice/mysql.service
└─2228 /usr/sbin/mysqld
Aug 21 11:10:40 debian11 systemd[1]: Starting MySQL Community Server...
Aug 21 11:10:46 debian11 systemd[1]: Started MySQL Community Server.
systemctl is-enabled mysql
enabled
您可以分别使用以下命令停止/启动/重启;
systemctl stop mysql
systemctl start mysql
systemctl restart mysql
在 Debian 11 上安全安装 MySQL 8
MySQL 附带一个名为的安全脚本 mysql_secure_installation
,使您能够通过以下方式实现 MySQL 安装的初始安全性:
- 您可以为 root 帐户设置密码。
- 您可以删除可从本地主机外部访问的 root 帐户。
- 您可以删除匿名用户帐户。
- 您可以删除 test 数据库(默认情况下,所有用户,甚至匿名用户都可以访问它),以及允许任何人访问名称以 test_ 开头的数据库的权限。
脚本可以通过运行简单地执行;
mysql_secure_installation
运行时,脚本会提示您是否要实施密码复杂性检查。接受选择密码强度;
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy:
LOW Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
...
接下来,设置 root 密码并接受其他提示以删除匿名数据库用户、禁止远程 root 登录、删除测试数据库和重新加载权限表以影响 MySQL 的更改。
检查安装的 MySQL 版本
您可以通过执行来验证安装的 MySQL 版本;
mysql -V
mysql Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)
登录 MySQL 8
您现在可以使用刚刚在上面设置的密码以 root 用户身份连接到 MySQL 8。
mysql -u root -p
登录MySQL后,您也可以通过执行命令查看版本;
mysql> SHOW VARIABLES LIKE "%version%";
+--------------------------+-------------------------------+
| Variable_name | Value |
+--------------------------+-------------------------------+
| admin_tls_version | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |
| immediate_server_version | 999999 |
| innodb_version | 8.0.26 |
| original_server_version | 999999 |
| protocol_version | 10 |
| replica_type_conversions | |
| slave_type_conversions | |
| tls_version | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |
| version | 8.0.26 |
| version_comment | MySQL Community Server - GPL |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
| version_compile_zlib | 1.2.11 |
+--------------------------+-------------------------------+
13 rows in set (0.06 sec)
mysql>
你去吧。
这标志着我们关于如何在 Debian 11 上安装 MySQL 8 的指南的结束。