Mysql 5.7 for windows 免安装版(解压版)安装和配置

网上写的不近详细,这里重新整理下。

准备:

1、windows操作系统

2、mysql 的解压版压缩文件

Mysql 5.7 for windows 免安装版(解压版)安装和配置

第一步:

解压mysql的压缩包到你的安装目录,因为是虚拟机,这里我就安装在C盘下:C:\mysql-5.7.18-win32

第二步:

配置环境变量

Mysql 5.7 for windows 免安装版(解压版)安装和配置

在系统变量下找到Path这个值,

Mysql 5.7 for windows 免安装版(解压版)安装和配置

点击编辑修改,

Mysql 5.7 for windows 免安装版(解压版)安装和配置

后面添加的路径是mysql的安装路径+\bin,比如我的安装路径是 C:\mysql-5.7.18-win32

则需要添加的是 C:\mysql-5.7.18-win32\bin

注意:添加之前看结尾有没有分号,没有记得加分号再添加。

第三步:

进入mysql安装目录下的bin文件夹,安装mysql

以管理员身份运行cmd,

依次运行下列命令:

1、cd C:\mysql-5.7.18-win32\bin                   //进入安装目录下的bin文件夹

Mysql 5.7 for windows 免安装版(解压版)安装和配置

2、mysqld --install                                    //安装mysqld服务

Mysql 5.7 for windows 免安装版(解压版)安装和配置

3、配置my.ini文件

1)需要你在安装目录下新建一个名为my.ini文件,.ini是后缀名。

2)然后在安装目录下新建一个名为data的文件夹。

如图:

Mysql 5.7 for windows 免安装版(解压版)安装和配置

 

把下面代码复制到my.ini文件中,保存。

注意:代码中红色字是需要改成你自己的目录。

# 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.
[client]
port = 3306
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.
character_set_server=utf8
init_connect='SET NAMES utf8'
basedir = C:\mysql-5.7.18-win32       
datadir = C:\mysql-5.7.18-win32\data
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 

 注意:

basedir = C:\mysql-5.7.18-win32       //这里改成你自己的安装目录
datadir = C:\mysql-5.7.18-win32\data   //改成 安装目录\data    这个路径存放你的数据文件

 4、初始化mysql

同样是在mysql安装目录下的bin文件夹内,

执行下面命令:

mysqld --defaults-file=C:\mysql-5.7.18-win32\my.ini --initialize --console

运行结果如下:

Mysql 5.7 for windows 免安装版(解压版)安装和配置

红框内是产生的随机密码,把它记录下来。待会登录mysql要用。

5、启动并登录mysql

依次运行下面命令:

1)net start mysql

Mysql 5.7 for windows 免安装版(解压版)安装和配置

2)mysql -u root -p

Mysql 5.7 for windows 免安装版(解压版)安装和配置

要求你输入密码,把上面产生的随机密码输入,注意大小写。

出现红框里的内容表示的登录成功。

Mysql 5.7 for windows 免安装版(解压版)安装和配置

6、重设登录密码

运行下面命令

set password for [email protected]=password('123456');           //单引号里面是你自己的密码,可以改成你自己的密码

 Mysql 5.7 for windows 免安装版(解压版)安装和配置

出现如上图界面表示成功。

 

7、用新密码重新登录(实验新密码对不对,这步也可以不用操作)

Mysql 5.7 for windows 免安装版(解压版)安装和配置

 

 

 OK,到这里已全部完事。