本文将介绍怎样在 Windows 系统上安装 zip 版本的 MySQL5.7,详细步骤如下。
浏览器访问 https://dev.mysql.com/downloads/mysql/ 地址,根据自己操作系统选择 MySQL5.7 安装包。
将下载的 MySQL5.7 安装包解压到指定的目录。
在 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使用 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 需要修改密码。
使用 “mysqld --install 服务名”命令将 mysql 安装成 Windows 服务,如下:
D:\mysql-5.7.24-winx64\bin> mysqld --install mysql
Service successfully installed.注意:上面命令将 mysql5.7 安装成名为 mysql 的服务。
D:\mysql-5.7.24-winx64\bin> net start mysql
mysql 服务正在启动 .
mysql 服务已经启动成功。使用 mysql -u -p 命令连接到 mysql,如下:
D:\server\mysql-8.0.25-winx64\bin>mysql -uroot -p
Enter password: 这里输入临时密码将 root 用户的密码修改为 aaaaaa,如下:
mysql> ALTER user 'root'@'localhost' IDENTIFIED BY 'aaaaaa';
Query OK, 0 rows affected (0.01 sec)下面将上面的命令使用 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@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@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@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