MySQL 5.7.17 安装教程

下载MySQL 5.7.17

win64 下载地址: mysql-5.7.17-winx64.zip
官网地址

解压安装包

1
E:\Mysql5.7.17\mysql-5.7.17-winx64

创建一个空文件夹,命名为 data

1
E:\Mysql5.7.17\mysql-5.7.17-winx64\data

配置启动文件

copy 安装目录下的 my-default.ini,重命名为 my.ini,修改参数如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/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.

[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 = .....
# port = .....
# server_id = .....

#########################
# basedir 为安装文件解压后的目录 | basedir和datadir 可以使用相对路径
# basedir=./..
basedir=E:\Mysql5.7.17\mysql-5.7.17-winx64
# datadir 为用来存放数据的目录
# datadir=./../data
datadir=E:\Mysql5.7.17\mysql-5.7.17-winx64\data
# port 为端口号
port=3306
# mar_connections为最大连接数
max_connections=20
character_set_server=utf8


# 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

explicit_defaults_for_timestamp=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

初始化数据目录

1
mysqld --defaults-file="E:\Mysql5.7.17\mysql-5.7.17-winx64\my.ini" --initialize-insecure

注意:
1.这个命令很重要,它会初始化 data 目录,在执行此命令前请先把 data 目录下的所有文件先删除,否则会失败
2.可以选择用 –initialize-insecure 或者 –initialize 来初始化,–initialize-insecure 初始化 root 密码为空,如果用 –initialize 来初始化,会产生一个随机密码
3.MySQL5.7 和 5.6 不太相同,要自己初始化数据 data 目录,不然启动不会成功

安装MySQL服务

1
mysqld -install

如果机器上已有 mysql,则使用以下命令:

1
mysqld install MySQL2  --defaults-file="E:\Mysql5.7.17\mysql-5.7.17-winx64\my.ini"

注意:这里一定要写绝对路径!

如果安装第二个 MySQL,则需要修改注册表,否则跳过这一步骤

HKEY_LOCAL_MACHINE–>SYSTEM–>CurrentControlSet–>Services
找到刚才创建的 MySQL2,将 ImagePath 修改成如下”:
E:\Mysql5.7.17\mysql-5.7.17-winx64\bin\mysqld“ –defaults-file=”E:\Mysql5.7.17\mysql-5.7.17-winx64\my.ini” MySQL2

启动MySQL服务

1
net start mysql(mysql2)
查看评论