Windows 安装 zip 版本的 MySQL7.5

本文将介绍怎样在 Windows 上安装 zip 包版本的 MySQL7.5。

本文将介绍怎样在 Windows 系统上安装 zip 版本的 MySQL5.7,详细步骤如下。

下载 MySQL8

浏览器访问 https://dev.mysql.com/downloads/mysql/ 地址,根据自己操作系统选择 MySQL5.7 安装包。

解压安装包

将下载的 MySQL5.7 安装包解压到指定的目录。

创建 my.ini

在 MySQL 的主目录下面创建 my.ini 配置文件,内容如下:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0.13/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysql]
default-character-set=utf8

[mysqld]

# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M

# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin

# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# bind-address = 127.0.0.1
port = 3306
# server_id = .....


# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

character_set_server=utf8
lower_case_table_names=1

初始化MySQL5.7

使用 mysqld --initialize 命令初始化 MySQL,初始化后将生成 data 目录,该目录存放了 MySQL 初始化的数据库(mysql、sys、information_schema、performance_schema 数据库)。命令如下:

D:\mysql-5.7.24-winx64\bin> mysqld --initialize --user=mysql --console
2022-12-02T05:12:45.824759Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-12-02T05:12:45.824828Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2022-12-02T05:12:45.824834Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2022-12-02T05:12:46.272460Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-12-02T05:12:46.327303Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-12-02T05:12:46.428215Z 0 [Warning] 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: f54ad475-71ff-11ed-888c-68f728833166.
2022-12-02T05:12:46.431579Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-12-02T05:12:46.437519Z 1 [Note] A temporary password is generated for root@localhost: jgdII2OCuN;s

注意:上面的 jgdII2OCuN;s 是 root 用户临时密码,首次连接到 mysql 需要修改密码。

安装MySQL5.7

使用 “mysqld --install 服务名”命令将 mysql 安装成 Windows 服务,如下:

D:\mysql-5.7.24-winx64\bin> mysqld --install mysql
Service successfully installed.

注意:上面命令将 mysql5.7 安装成名为 mysql 的服务。

启动MySQL5.7

D:\mysql-5.7.24-winx64\bin> net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。

连接到 MySQL

使用 mysql -u -p 命令连接到 mysql,如下:

D:\server\mysql-8.0.25-winx64\bin>mysql -uroot -p
Enter password: 这里输入临时密码

修改 root 密码 

将 root 用户的密码修改为 aaaaaa,如下:

mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'aaaaaa';
Query OK, 0 rows affected (0.01 sec)

扩展功能

下面将上面的命令使用 bat 脚本按照功能进行分别保存。如下:

安装(install.bat)

@echo off
setlocal

if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :eof

:nt
set "CUR_DIR=%~dp0"

echo install MySql Server
%CUR_DIR%bin\mysqld --install mysql5 --defaults-file=%CUR_DIR%my.ini

pause

卸载(uninstall.bat)

@echo off
setlocal

if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :eof

:nt
set "CUR_DIR=%~dp0"

echo uninstall MySql Server
%CUR_DIR%bin\mysqld --remove mysql5

pause

启动(start.bat)

@echo off
setlocal

if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :eof

:nt
NET START mysql5

pause

停止(stop.bat)

@echo off
setlocal

if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :eof

:nt
NET STOP mysql5

pause
我们常常听人说,人们因工作过度而垮下来,但是实际上十有八九是因为饱受担忧或焦虑的折磨。 —— 卢伯克.J.
0 不喜欢
说说我的看法 -
全部评论(
没有评论
关于
本网站专注于 Java、数据库(MySQL、Oracle)、Linux、软件架构及大数据等多领域技术知识分享。涵盖丰富的原创与精选技术文章,助力技术传播与交流。无论是技术新手渴望入门,还是资深开发者寻求进阶,这里都能为您提供深度见解与实用经验,让复杂编码变得轻松易懂,携手共赴技术提升新高度。如有侵权,请来信告知:hxstrive@outlook.com
公众号