官方原文(Oracle):
https://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.html

Step 1:
将下载的ZIP包的安装介质解压到期望的软件目录。
在我的环境中,是这个路径【E:\app\MySQL_base\mysql-5.7.26-winx64】

其中,BIN目录已经加入到了MS Windows环境变量:
路径【E:\app\MySQL_base\mysql-5.7.26-winx64\bin】
这样,在普通的CMD与PowerShell中也可以随时访问到【mysql.exe】了。

Microsoft Windows [版本 10.0.18362.30]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Users\adamhuan>mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for Win64 (x86_64)

C:\Users\adamhuan>

创建MySQL的数据目录【E:\mysql_data】

Step 2:
配置MS Windows中的MySQL的配置文件(Option File)
对于MS Windows的系统来说,配置文件(my.cnf / my.ini)可以配置在这几个地址:
1. %WINDIR%\my.ini, %WINDIR%\my.cnf
2. C:\my.ini, C:\my.cnf
3. BASEDIR\my.ini, BASEDIR\my.cnf
4. defaults-extra-file
5. %APPDATA%\MySQL\.mylogin.cnf

更具体的说明可以参考:
https://dev.mysql.com/doc/refman/5.7/en/option-files.html

先看看我的当前MS Windows的环境变量WINDIR在哪里:

C:\Users\adamhuan>echo %WINDIR%
C:\Windows

C:\Users\adamhuan>

这里,我选择在【BASEDIR】里面创建。
在我的环境里,【BASEDIR】是【E:\app\MySQL_base\mysql-5.7.26-winx64】
因此,我的MySQL配置文件路径是【E:\app\MySQL_base\mysql-5.7.26-winx64\my.ini】

文件:my.ini

[mysql]

# MySQL 客户端

# 字符集 - 默认
default-character-set = utf8

[mysqld]

# MySQL 服务端

# MySQL - basedir: software installation path 软件安装目录
basedir = E:\\app\\MySQL_base\\mysql-5.7.26-winx64

# MySQL - datadir: the location for data storage 数据存放目录
datadir = E:\\mysql_data

# Character Set - 字符集
character-set-server = utf8

# MySQL - Service Port
port = 3306

# MySQL - 允许的最大连接数
max_connections = 200

# MySQL - 存储引擎 - 默认
default-storage-engine = INNODB

然后,根据配置文件,初始化数据目录:

Microsoft Windows [版本 10.0.18362.30]
(c) 2019 Microsoft Corporation。保留所有权利。

C:\Windows\system32>mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for Win64 (x86_64)

C:\Windows\system32>mysqld -V
mysqld  Ver 5.7.26 for Win64 on x86_64 (MySQL Community Server (GPL))

C:\Windows\system32>
C:\Windows\system32>mysqld --initialize

C:\Windows\system32>

数据目录初始化后:

C:\Users\adamhuan>e:

E:\>cd mysql_data

E:\mysql_data>dir
 驱动器 E 中的卷是 新加卷
 卷的序列号是 86A4-FA5E

 E:\mysql_data 的目录

2019/05/30  08:45              .
2019/05/30  08:45              ..
2019/05/30  08:45                56 auto.cnf
2019/05/30  08:45        12,582,912 ibdata1
2019/05/30  08:45               505 ib_buffer_pool
2019/05/30  08:45        50,331,648 ib_logfile0
2019/05/30  08:45        50,331,648 ib_logfile1
2019/05/30  08:45              mysql
2019/05/30  08:45              performance_schema
2019/05/30  08:45              sys
2019/05/30  08:45               808 wonderme.err
               6 个文件    113,247,577 字节
               5 个目录 378,950,377,472 可用字节

E:\mysql_data>

配置MySQL在MS Windows中的服务

配置前:

C:\Users\adamhuan>sc query mysql
[SC] EnumQueryServicesStatus:OpenService 失败 1060:

指定的服务未安装。


C:\Users\adamhuan>

配置:

C:\Windows\system32>mysqld install
Service successfully installed.

C:\Windows\system32>

配置后:

C:\Users\adamhuan>sc query mysql

SERVICE_NAME: mysql
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 1077  (0x435)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

C:\Users\adamhuan>

MS Windows,启动MySQL服务:

C:\Windows\system32>sc query mysql

SERVICE_NAME: mysql
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 1077  (0x435)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

C:\Windows\system32>
C:\Windows\system32>sc start mysql

SERVICE_NAME: mysql
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 2  START_PENDING
                                (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x3
        WAIT_HINT          : 0x3a98
        PID                : 13504
        FLAGS              :

C:\Windows\system32>
C:\Windows\system32>sc query mysql

SERVICE_NAME: mysql
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

C:\Windows\system32>

可以看到,MySQL的系统服务已经在运行了。

查看一下MySQL的口令:
MySQL的默认生成的口令,是在数据目录的【*.err】错误日志中可以查看到的。

C:\Windows\system32>e:

E:\>cd mysql_data

E:\mysql_data>dir | findstr ".err"
2019/05/30  09:21             3,835 wonderme.err

E:\mysql_data>

E:\mysql_data>type wonderme.err
2019-05-30T00:45:26.530878Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-30T00:45:30.458257Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-05-30T00:45:31.024293Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-05-30T00:45:31.345740Z 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: 3a0ecb9b-8274-11e9-97d0-54ee750589c1.
2019-05-30T00:45:31.415820Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-05-30T00:45:31.439988Z 1 [Note] A temporary password is generated for root@localhost: akyhuDlt;0DL
2019-05-30T01:20:17.584764Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-05-30T01:20:17.584845Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2019-05-30T01:20:17.585234Z 0 [Note] MySQL (mysqld 5.7.26) starting as process 13504 ...
2019-05-30T01:20:17.592550Z 0 [Note] InnoDB: Mutexes and rw_locks use Windows interlocked functions
2019-05-30T01:20:17.593177Z 0 [Note] InnoDB: Uses event mutexes
2019-05-30T01:20:17.593626Z 0 [Note] InnoDB: _mm_lfence() and _mm_sfence() are used for memory barrier
2019-05-30T01:20:17.594269Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-05-30T01:20:17.595017Z 0 [Note] InnoDB: Number of pools: 1
2019-05-30T01:20:17.595479Z 0 [Note] InnoDB: Not using CPU crc32 instructions
2019-05-30T01:20:17.598890Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2019-05-30T01:20:17.604680Z 0 [Note] InnoDB: Completed initialization of buffer pool
2019-05-30T01:20:17.672284Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2019-05-30T01:20:17.863512Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-05-30T01:20:17.864564Z 0 [Note] InnoDB: Setting file '.\ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-05-30T01:20:18.105234Z 0 [Note] InnoDB: File '.\ibtmp1' size is now 12 MB.
2019-05-30T01:20:18.110007Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2019-05-30T01:20:18.111902Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2019-05-30T01:20:18.113849Z 0 [Note] InnoDB: Waiting for purge to start
2019-05-30T01:20:18.171218Z 0 [Note] InnoDB: 5.7.26 started; log sequence number 2526049
2019-05-30T01:20:18.173344Z 0 [Note] InnoDB: Loading buffer pool(s) from E:\mysql_data\ib_buffer_pool
2019-05-30T01:20:18.173386Z 0 [Note] Plugin 'FEDERATED' is disabled.
2019-05-30T01:20:18.281590Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2019-05-30T01:20:18.284021Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
2019-05-30T01:20:18.287482Z 0 [Note] IPv6 is available.
2019-05-30T01:20:18.288426Z 0 [Note]   - '::' resolves to '::';
2019-05-30T01:20:18.289941Z 0 [Note] Server socket created on IP: '::'.
2019-05-30T01:20:18.640530Z 0 [Note] InnoDB: Buffer pool(s) load completed at 190530  9:20:18
2019-05-30T01:20:18.669916Z 0 [Note] Event Scheduler: Loaded 0 events
2019-05-30T01:20:18.670560Z 0 [Note] MySQL: ready for connections.
Version: '5.7.26'  socket: ''  port: 3306  MySQL Community Server (GPL)
2019-05-30T01:20:58.680071Z 2 [Note] Access denied for user 'root'@'localhost' (using password: NO)
2019-05-30T01:21:10.064658Z 3 [Note] Access denied for user 'root'@'localhost' (using password: NO)

E:\mysql_data>

E:\mysql_data>type wonderme.err | findstr "password" | findstr "temporary"
2019-05-30T00:45:31.439988Z 1 [Note] A temporary password is generated for root@localhost: akyhuDlt;0DL

E:\mysql_data>

使用临时口令登录:

E:\mysql_data>mysql -u root -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.26

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

可以看到,需要修改临时口令。

修改临时口令:

mysql> ALTER USER USER() IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

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

mysql>

这样就好了。

——————————————————
Done。