1. 首先将下载完成zip包解压到某个目录,如:E:\mysql-5.7.16-winx64

  2. 修改环境变量path增加E:\mysql-5.7.16-winx64\bin

  3. 在E:\mysql-5.7.16-winx64目录中新建目录data,将默认的my-default.ini复制为my.ini,同时配置以上字段:

basedir = E:\mysql-5.7.16-winx64datadir = E:\mysql-5.7.16-winx64\dataport = 3306server_id = 1

将最后一行注释,如果不注释也不影响,安装时会 有一些报错信息,但不影响使用

#sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

安装MySQL服务,注意一定要在mysql的bin目录下安装

E:\mysql-5.7.16-winx64\bin>mysqld --install MySQL

如果不是,可能在启动服务时出现如下错误:

发生系统错误 2。系统找不到指定的文件。

此时需要移除mysql服务重新安装

mysqld --remove MySQLService successfully removed.

初始化MySQL,以管理员身份运行cmd,进入到mysql的bin目录运行

mysqld --initialize   --explicit_defaults_for_timestamp --console

mysql-5.7.16-winx64\bin>mysqld --initialize   --explicit_defaults_for_timestamp --console2016-10-15T04:38:46.341663Z 0 [Warning] InnoDB: New log files created, LSN=457902016-10-15T04:38:46.908164Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.2016-10-15T04:38:47.161759Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.2016-10-15T04:38:47.182800Z 1 [Note] A temporary password is generated for root@localhost: K9Otza#ftMss

注意看最后一行 的密码输出

A temporary password is generated for root@localhost: K9Otza#ftMss

如果想重新初始化,需要清空data目录下的数据,否则会出现如下报错:

mysqld --initialize   --explicit_defaults_for_timestamp --console2016-10-16T02:15:50.321689Z 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.2016-10-16T02:15:50.321689Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.2016-10-16T02:15:50.321689Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.2016-10-16T02:15:50.321689Z 0 [ERROR] Aborting

启动服务

E:\mysql-5.7.16-winx64\bin>net start MySQLMySQL 服务正在启动 .MySQL 服务已经启动成功。

以上面的密码登陆

E:\mysql-5.7.16-winx64\bin>mysql -uroot -pEnter password: ************Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.16Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exit

修改管理员密码:

E:\mysql-5.7.16-winx64\bin>mysqladmin -uroot -p passwordEnter password: ************New password: ******Confirm new password: ******

使用新密码登陆验证

E:\mysql-5.7.16-winx64\bin>mysql -uroot -p123456mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 6Server version: 5.7.16 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

关闭MySQL服务

E:\mysql-5.7.16-winx64\bin>mysqladmin -uroot -p shutdownEnter password: ******

启动MySQL服务

E:\mysql-5.7.16-winx64\bin>net start MySQLMySQL 服务正在启动 .MySQL 服务已经启动成功。