袂沐 发表于 2025-8-11 12:32:56

Windows 同时安装多个 MySQL

记一次在 Windows 环境下手动安装多个不同版本的 MySQL 的过程,并且设置手动启动服务,避免长时间占用后台资源。
1. 下载 MySQL 软件压缩包

下载网址:https://dev.mysql.com/downloads/mysql/
找到需要的 MySQL 版本,选择 Windows (x86, 64-bit), ZIP Archive 下载即可。
最新版本下载页面历史版本下载页面2. 解压缩

将上一步下载好的压缩包分别解压至合适的位置。

3. 创建配置文件

在 MySQL 软件根目录下创建名为 my.ini 的配置文件。

配置文件内容如下:

# 客户端默认字符集
default-character-set=utf8mb4
# 客户端连接的默认端口号
port=5744


# MySQL 服务的端口号(根据需要设置即可,我这里设置为与版本号一致)
port=5744
# MySQL 的安装目录
basedir="C:\dev\MySQL\mysql-5.7.44-winx64"
# 设置 MySQL 数据库的数据的存放目录
datadir="C:\dev\MySQL\mysql-5.7.44-winx64\data"
# 允许最大连接数
max_connections=20
# 字符集
character-set-server=utf8mb4
# 排序规则
collation-server=utf8mb4_general_ci
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB4. 初始化 MySQL

在 bin 目录下打开终端执行 .\mysqld.exe --initialize --console 命令以初始化 MySQL,初始化成功后将输出 root 用户的临时密码。例如下面的临时密码就是 p0q%adaOseZe。
C:\dev\MySQL\mysql-5.7.44-winx64\bin>.\mysqld.exe --initialize --console
2025-08-11T03:11:13.767360Z 0 TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-08-11T03:11:14.125029Z 0 InnoDB: New log files created, LSN=45790
2025-08-11T03:11:14.221824Z 0 InnoDB: Creating foreign key constraint system tables.
2025-08-11T03:11:14.318691Z 0 No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d6eb798b-7660-11f0-9b33-00ff84a6f5fe.
2025-08-11T03:11:14.324439Z 0 Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-08-11T03:11:14.661271Z 0 A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-08-11T03:11:14.661576Z 0 A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-08-11T03:11:14.665021Z 0 CA certificate ca.pem is self signed.
2025-08-11T03:11:14.802173Z 1 A temporary password is generated for root@localhost: p0q%adaOseZe5. 安装 MySQL 服务并启动

以管理员身份运行终端,cd 到 bin 目录下执行 .\mysqld.exe --install--defaults-file= 命令以安装 MySQL 服务。
执行 sc configstart=demand 命令以配置 MySQL 服务为手动启动。
执行 net start命令以启动 MySQL 服务。
服务名似乎不区分字母大小写,安装为 MySQL5744 的服务,使用 mysql5744 也能启动。
使用 net stop命令可停止 MySQL 服务。
使用 .\mysqld.exe --remove命令可卸载 MySQL 服务。
C:\Windows\system32>cd \dev\MySQL\mysql-5.7.44-winx64\bin

C:\dev\MySQL\mysql-5.7.44-winx64\bin>.\mysqld.exe --install MySQL5744 --defaults-file="C:\dev\MySQL\mysql-5.7.44-winx64\my.ini"
Service successfully installed.

C:\dev\MySQL\mysql-5.7.44-winx64\bin>sc config MySQL5744 start=demand
ChangeServiceConfig 成功

C:\dev\MySQL\mysql-5.7.44-winx64\bin>net start mysql5744
MySQL5744 服务正在启动 .
MySQL5744 服务已经启动成功。如果启动失败,可以到配置文件 my.ini 配置的数据存放目录查找 设备名称.err 的日志文件查看原因。
6. 修改 root 密码

在 bin 目录下执行 .\mysqladmin.exe -u root -p password命令以修改 root 用户的密码,执行后需输入初始化时显示的临时 root 用户密码。
C:\dev\MySQL\mysql-5.7.44-winx64\bin>.\mysqladmin.exe -u root -p password 1234
Enter password: ************
mysqladmin: Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.检查一下新密码是否可用。
C:\dev\MySQL\mysql-5.7.44-winx64\bin>.\mysql.exe -u root -p
Enter password: ****
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.44 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, 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>
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: Windows 同时安装多个 MySQL