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

Debian系列安装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所示。

t19

图19 下载APT仓库包

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

t20

图20 下载APT仓库包

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

t21

图21 下载APT仓库包

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

t22

图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所示。

t23

图23 选择MySQL版本

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

t24

图24 选择MySQL版本

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

t25

图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所示。

t26

图26 输入MySQL root用户密码

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

t27

图27 确认提示信息

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

t28

图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所示。

t29

图29 下载APT仓库包

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

t30

图30 下载APT仓库包

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

t31

图31 下载APT仓库包

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

t32

图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所示。

t33

图33 选择MySQL版本

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

t34

图34 选择MySQL版本

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

t35

图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所示。

t36

图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所示。

t37

图37 选择MySQL版本

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

t38

图38 选择MySQL版本

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

t39

图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所示。

t40

图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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Raymond运维

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值