参考: https://dev.mysql.com/doc/refman/5.7/en/windows-install-archive.html
下载MySQL
https://dev.mysql.com/downloads/mysql/ 选择 Windows (x86, 64-bit), ZIP Archive
MySQL Community 5.7 Server requires the Microsoft Visual C++ 2013 Redistributable Package to run on Windows platforms.
MySQL 5.7版本需要安装Microsoft Visual C++ 2013 Redistributable Package
下载安装: https://www.microsoft.com/en-us/download/details.aspx?id=40784
解压安装
1. 将下载的MySQL压缩包解压
如D:\dev_app\DB\mysql-5.7.20-winx64
目录下,
将D:\dev_app\DB\mysql-5.7.20-winx64\bin
加入到系统环境变量中
同时创建数据存储目录如:D:\dev_app\DB\mysql-5.7.20-winx64\data
2. 创建配置mysql.ini文件
As of MySQL 5.7.18, my-default.ini is no longer included in or installed by distribution packages.
MySQL 5.7.18之后,my-default.ini不在包含在分发包中,我们在D:\dev_app\DB\mysql-5.7.20-winx64
目录下自己创建一个my.ini
内容如下:
1 | # For advice on how to change settings please see |
初始化数据目录
管理员权限启动CMD, 使用mysqld初始化目录:1
C:\Users\Administrator>mysqld --defaults-file=D:\dev_app\DB\mysql-5.7.20-winx64\my.ini --initialize
data目录下会生成一个.err扩展名的文件,打开它,里面会记录生成的MySQL临时密码:1
2017-11-03T11:53:18.008877Z 1 [Note] A temporary password is generated for root@localhost: xd#pZirf&2Gk
执行目录初始化主要完成以下功能:
- 检查数据目录是否存在
- 创建mysql数据库及系统表等
- 初始化系统表空间等
- 服务器创建’root’@’localhost’ 超级用户帐户和其他保留帐户
- 其他
启动MySQL
1 | # 可以不带console参数,日志写到文件中,不在屏幕上输出 |
启动成功1
2
3
4
5
6
7
8
92017-11-03T12:06:51.583410Z 0 [Note] .\bin\mysqld.exe: ready for connections.
Version: '5.7.20' socket: '' port: 3306 MySQL Community Server (GPL)
2017-11-03T12:06:51.583410Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA
.TABLES;' to get a list of tables using the deprecated partition engine. You may
use the startup option '--disable-partition-engine-check' to skip this check.
2017-11-03T12:06:51.584410Z 0 [Note] Beginning of list of non-natively partition
ed tables
2017-11-03T12:06:51.602411Z 0 [Note] End of list of non-natively partitioned tab
les
连接到MySQL
1 | C:\Users\Administrator>mysql -u root -p |
分配一个新的root密码
1 | mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; |
将MySQL作为windows服务
确保mysql服务停止
1 | C:\Users\Administrator>mysqladmin -u root -p shutdown |
将MySQL Server作为Windows Service自动启动
1 | C:\Users\Administrator>mysqld --install |
移除MySQL服务1
C:\Users\Administrator>mysqld --remove