MySQL包安装 -- Debian系列(Apt资源库安装MySQL)

举报
Raymond运维 发表于 2025/10/06 20:45:27 2025/10/06
【摘要】 MySQL包安装 -- Debian系列(Apt资源库安装MySQL)

2.2.2 Debian系列

2.2.2.1 Apt资源库安装MySQL

2.2.2.1.1 MySQL 8.0

在“Ubuntu”上安装MySQL:

root@ubuntu2404:~# apt-cache madison mysql-server
mysql-server | 8.0.43-0ubuntu0.24.04.2 | https://mirrors.aliyun.com/ubuntu noble-updates/main amd64 Packages
mysql-server | 8.0.43-0ubuntu0.24.04.1 | https://mirrors.aliyun.com/ubuntu noble-security/main amd64 Packages
mysql-server | 8.0.36-2ubuntu3 | https://mirrors.aliyun.com/ubuntu noble/main amd64 Packages

root@ubuntu2404:~# apt install -y mysql-server

root@ubuntu2404:~# systemctl enable --now mysql

root@ubuntu2404:~# ls /var/lib/mysql
 auto.cnf        ca-key.pem       '#ib_16384_0.dblwr'  '#innodb_redo'        private_key.pem   ubuntu2404.pid
 binlog.000001   ca.pem           '#ib_16384_1.dblwr'  '#innodb_temp'        public_key.pem    undo_001
 binlog.000002   client-cert.pem   ib_buffer_pool       mysql                server-cert.pem   undo_002
 binlog.000003   client-key.pem    ibdata1              mysql.ibd            server-key.pem
 binlog.index    debian-5.7.flag   ibtmp1               performance_schema   sys

root@ubuntu2404:~# mysql -V
mysql  Ver 8.0.43-0ubuntu0.24.04.2 for Linux on x86_64 ((Ubuntu))

root@ubuntu2404:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-10-01 16:34:50 CST; 35s ago
   Main PID: 1925 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 2210)
     Memory: 363.8M (peak: 378.0M)
        CPU: 1.178s
     CGroup: /system.slice/mysql.service
             └─1925 /usr/sbin/mysqld

Oct 01 16:34:50 ubuntu2404 systemd[1]: Starting mysql.service - MySQL Community Server...
Oct 01 16:34:50 ubuntu2404 systemd[1]: Started mysql.service - MySQL Community Server.

root@ubuntu2404:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.43-0ubuntu0.24.04.2 (Ubuntu)

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.0.43-0ubuntu0.24.04.2 for Linux on x86_64 ((Ubuntu))

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.43-0ubuntu0.24.04.2 (Ubuntu)
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			1 min 19 sec

Threads: 2  Questions: 5  Slow queries: 0  Opens: 119  Flush tables: 3  Open tables: 38  Queries per second avg: 0.063
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

在“Debian 11/12”上安装MySQL:

去“https://www.mysql.com/”网站下载,选择“DOWNLOADS”,如图19所示。

图19 下载APT仓库包

选择“MySQL Community (GPL) Downloads”,如图20所示。

图20 下载APT仓库包

选择“MySQL APT Repository(MySQL APT资源库)”,如图21所示。

图21 下载APT仓库包

然后选择”DEB Package“后面的”Download“,如图22所示。

图22 下载APT仓库包

root@debian12:~# wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb

root@debian12:~# dpkg -i mysql-apt-config_0.8.34-1_all.deb
Selecting previously unselected package mysql-apt-config.
dpkg: regarding mysql-apt-config_0.8.34-1_all.deb containing mysql-apt-config, pre-dependency problem:
 mysql-apt-config pre-depends on gnupg
  gnupg is not installed.  # 提示没有安装gnupg

dpkg: error processing archive mysql-apt-config_0.8.34-1_all.deb (--install):
 pre-dependency problem - not installing mysql-apt-config
Errors were encountered while processing:
 mysql-apt-config_0.8.34-1_all.deb

root@debian12:~# apt install -y gnupg

root@debian12:~# dpkg -i mysql-apt-config_0.8.34-1_all.deb

使用箭头键导航到 “MySQL Server & Cluster (Currently selected: mysql-8.4-lts)” 选项,然后按下 Enter 键,这将允许你选择具体的 MySQL 服务器版本,如图23所示。

图23 选择MySQL版本

在版本选择界面中,选择 “mysql-8.0” 版本并按 Enter,如图24所示。

图24 选择MySQL版本

使用箭头键导航到 “Ok” 选项,按下 Enter 键,确认并保存配置,如图25所示。

图25 确认选择

# 替换国内镜像源
sed -i.bak 's|http://repo.mysql.com|https://mirrors.nju.edu.cn/mysql|g' /etc/apt/sources.list.d/mysql.list

root@debian12:~# apt update

root@debian12:~# apt-cache madison mysql-community-server
mysql-community-server | 8.0.43-1debian12 | http://repo.mysql.com/apt/debian bookworm/mysql-8.0 amd64 Packages
mysql-community | 8.0.43-1debian12 | http://repo.mysql.com/apt/debian bookworm/mysql-8.0 Sources

root@debian12:~# apt install -y mysql-community-server

输入MySQL root用户密码,然后按下 Enter 键,如图26所示。

图26 输入MySQL root用户密码

在下面提示直接按下 Enter 键,如图27所示。

图27 确认提示信息

选择“Use Strong Password Encryption (RECOMMENDED)”,然后按下 Enter 键,如图28所示。

图28 选择默认身份验证插件

root@debian12:~# systemctl enable --now mysql

root@debian12:~# ls /var/lib/mysql
 auto.cnf	 ca.pem		      ib_buffer_pool   mysql		    server-cert.pem
 binlog.000001	 client-cert.pem      ibdata1	       mysql.ibd	    server-key.pem
 binlog.000002	 client-key.pem       ibtmp1	       performance_schema   sys
 binlog.index	'#ib_16384_0.dblwr'  '#innodb_redo'    private_key.pem	    undo_001
 ca-key.pem	'#ib_16384_1.dblwr'  '#innodb_temp'    public_key.pem	    undo_002

root@debian12:~# mysql -V
mysql  Ver 8.0.43 for Linux on x86_64 (MySQL Community Server - GPL

root@debian12:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Wed 2025-10-01 17:29:03 CST; 50s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 1923 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 2273)
     Memory: 368.3M
        CPU: 1.349s
     CGroup: /system.slice/mysql.service
             └─1923 /usr/sbin/mysqld

Oct 01 17:29:02 debian12 systemd[1]: Starting mysql.service - MySQL Community Server...
Oct 01 17:29:03 debian12 systemd[1]: Started mysql.service - MySQL Community Server.

root@debian12:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.43 MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.0.43 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.43 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			1 min 16 sec

Threads: 2  Questions: 5  Slow queries: 0  Opens: 119  Flush tables: 3  Open tables: 38  Queries per second avg: 0.065
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
2.2.2.1.2 MySQL 8.4

去“https://www.mysql.com/”网站下载,选择“DOWNLOADS”,如图29所示。

图29 下载APT仓库包

选择“MySQL Community (GPL) Downloads”,如图30所示。

图30 下载APT仓库包

选择“MySQL APT Repository(MySQL APT资源库)”,如图31所示。

图31 下载APT仓库包

然后选择”DEB Package“后面的”Download“,如图32所示。

图32 下载APT仓库包

在“Ubuntu"上安装MySQL:

root@ubuntu2404:~# wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb

root@ubuntu2404:~# dpkg -i mysql-apt-config_0.8.34-1_all.deb

使用箭头键导航到 “MySQL Server & Cluster (Currently selected: mysql-8.4-lts)” 选项,然后按下 Enter 键,这将允许你选择具体的 MySQL 服务器版本,如图33所示。

图33 选择MySQL版本

在版本选择界面中,选择 “mysql-8.4-lts” 版本(或其他你想要的版本)并按 Enter,如图34所示。

图34 选择MySQL版本

使用箭头键导航到 “Ok” 选项,按下 Enter 键,确认并保存配置,如图35所示。

图35 确认选择

# 替换国内镜像源
sed -i.bak 's|http://repo.mysql.com|https://mirrors.nju.edu.cn/mysql|g' /etc/apt/sources.list.d/mysql.list

root@ubuntu2404:~# apt update

root@ubuntu2404:~# apt-cache madison mysql-community-server
mysql-community-server | 8.4.6-1ubuntu24.04 | http://repo.mysql.com/apt/ubuntu noble/mysql-8.4-lts amd64 Packages
mysql-community | 8.4.6-1ubuntu24.04 | http://repo.mysql.com/apt/ubuntu noble/mysql-8.4-lts Sources

root@ubuntu2404:~# apt install -y  mysql-community-server

输入MySQL root用户密码,然后按下 Enter 键,如图36所示。

图36 输入MySQL root用户密码

root@ubuntu2404:~# systemctl enable --now mysql

root@ubuntu2404:~# ls /var/lib/mysql
 auto.cnf        ca.pem               ib_buffer_pool   mysql                   public_key.pem    undo_002
 binlog.000001   client-cert.pem      ibdata1          mysql.ibd               server-cert.pem
 binlog.000002   client-key.pem       ibtmp1           mysql_upgrade_history   server-key.pem
 binlog.index   '#ib_16384_0.dblwr'  '#innodb_redo'    performance_schema      sys
 ca-key.pem     '#ib_16384_1.dblwr'  '#innodb_temp'    private_key.pem         undo_001

root@ubuntu2404:~# mysql -V
mysql  Ver 8.4.6 for Linux on x86_64 (MySQL Community Server - GPL)

root@ubuntu2404:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-10-03 10:55:17 CST; 36s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 2134 (mysqld)
     Status: "Server is operational"
      Tasks: 35 (limit: 2210)
     Memory: 420.3M (peak: 434.3M)
        CPU: 1.415s
     CGroup: /system.slice/mysql.service
             └─2134 /usr/sbin/mysqld

Oct 03 10:55:16 ubuntu2404 systemd[1]: Starting mysql.service - MySQL Community Server...
Oct 03 10:55:17 ubuntu2404 systemd[1]: Started mysql.service - MySQL Community Server.

root@ubuntu2404:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.6 MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.6 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.6 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			57 sec

Threads: 2  Questions: 6  Slow queries: 0  Opens: 119  Flush tables: 3  Open tables: 38  Queries per second avg: 0.105
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)

mysql> exit
Bye

在"Debian 11/12"上安装MySQL:

root@debian12:~# wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb

root@debian12:~# dpkg -i  mysql-apt-config_0.8.34-1_all.deb
dpkg: regarding mysql-apt-config_0.8.34-1_all.deb containing mysql-apt-config, pre-dependency problem:
 mysql-apt-config pre-depends on gnupg
  gnupg is not installed. # 提示没有安装gnupg

dpkg: error processing archive mysql-apt-config_0.8.34-1_all.deb (--install):
 pre-dependency problem - not installing mysql-apt-config
Errors were encountered while processing:
 mysql-apt-config_0.8.34-1_all.deb

root@debian12:~# apt install -y gnupg

root@debian12:~# dpkg -i  mysql-apt-config_0.8.34-1_all.deb

使用箭头键导航到 “MySQL Server & Cluster (Currently selected: mysql-8.4-lts)” 选项,然后按下 Enter 键,这将允许你选择具体的 MySQL 服务器版本,如图37所示。

图37 选择MySQL版本

在版本选择界面中,选择 “mysql-8.4-lts” 版本(或其他你想要的版本)并按 Enter,如图38所示。

图38 选择MySQL版本

使用箭头键导航到 “Ok” 选项,按下 Enter 键,确认并保存配置,如图39所示。

图39 确认选择

# 替换国内镜像源
sed -i.bak 's|http://repo.mysql.com|https://mirrors.nju.edu.cn/mysql|g' /etc/apt/sources.list.d/mysql.list

root@debian12:~# apt update

root@debian12:~# apt-cache madison mysql-community-server
mysql-community-server | 8.4.6-1debian12 | http://repo.mysql.com/apt/debian bookworm/mysql-8.4-lts amd64 Packages
mysql-community | 8.4.6-1debian12 | http://repo.mysql.com/apt/debian bookworm/mysql-8.4-lts Sources

root@debian12:~# apt install -y  mysql-community-server

输入MySQL root用户密码,然后按下 Enter 键,如图40所示。

图40 输入MySQL root用户密码

root@debian12:~# systemctl enable --now mysql

root@debian12:~# ls /var/lib/mysql
 auto.cnf	 ca.pem		      ib_buffer_pool   mysql		       public_key.pem	 undo_002
 binlog.000001	 client-cert.pem      ibdata1	       mysql.ibd	       server-cert.pem
 binlog.000002	 client-key.pem       ibtmp1	       mysql_upgrade_history   server-key.pem
 binlog.index	'#ib_16384_0.dblwr'  '#innodb_redo'    performance_schema      sys
 ca-key.pem	'#ib_16384_1.dblwr'  '#innodb_temp'    private_key.pem	       undo_001

root@debian12:~# mysql -V
mysql  Ver 8.4.6 for Linux on x86_64 (MySQL Community Server - GPL)

root@debian12:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Fri 2025-10-03 11:02:19 CST; 29s ago
       Docs: man:mysqld(8)
             http://dev.mysql.com/doc/refman/en/using-systemd.html
   Main PID: 1907 (mysqld)
     Status: "Server is operational"
      Tasks: 35 (limit: 2273)
     Memory: 427.9M
        CPU: 1.051s
     CGroup: /system.slice/mysql.service
             └─1907 /usr/sbin/mysqld

Oct 03 11:02:18 debian12 systemd[1]: Starting mysql.service - MySQL Community Server...
Oct 03 11:02:19 debian12 systemd[1]: Started mysql.service - MySQL Community Server.

root@debian12:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.6 MySQL Community Server - GPL

Copyright (c) 2000, 2025, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> status
--------------
mysql  Ver 8.4.6 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.6 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			51 sec

Threads: 2  Questions: 6  Slow queries: 0  Opens: 119  Flush tables: 3  Open tables: 38  Queries per second avg: 0.117
--------------

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。