---
title: "win10 安装mysql5.7.21"
author: "yjph83"
date: "2018-06-15T11:02:42Z"
tags: []
categories: ["开源软件"]
slug: "win10-mysql5-7-21"
draft: false
lastmod: "2018-06-15T11:02:42Z"
id: 2425025
url: "https://yjph83.iteye.com/blog/2425025"
---

[http://yjph83.iteye.com/blog/2205063](/blog/2205063 "mysql5.x 在windows下安装") （mysql5.x 在windows下安装）

 

1、从官网下载MySQL5.7.21解压版64位

 

2、解压（我的解压路径为：H:\\mysql-5.7.21-winx64，我将其改名去掉-，并移动到此位置H:\\develop\\mysql5.7.21。

 

3、添加环境变量（系统变量）：

 

　　变量名：MYSQL\_HOME

 

　　变量值：H:\\develop\\mysql5.7.21

 

　修改系统变量path，在path原有值后添加路径：%MYSQL\_HOME%\\bin。

  以管理员身份运行命令行工具：

  H:\\&gt;mysqld --version

  mysqld  Ver 5.7.21 for Win64 on x86\_64 (MySQL Community Server (GPL))

  

  

 

4、在H:\\develop\\mysql5.7.21路径下新建配置文件：my.ini，在my.ini中保存以下内容：

\[mysqld]

\#### database configure

basedir=H:\\develop\\mysql5.7.21

datadir=H:\\develop\\mysql5.7.21\\data\\

user=mysql

symbolic-links=0

 

\#### skip configuration

\# skip-name-resolve

 

\#### innodb\_configuration

innodb\_file\_per\_table=1

innodb\_open\_files=4096

innodb\_buffer\_pool\_size=1024M

innodb\_log\_group\_home\_dir=H:\\develop\\mysql5.7.21\\mysqllog

 

\#### character set

character-set-server=utf8

collation-server=utf8\_general\_ci

lower-case-table-names=1

 

\#### log configure

pid-file=H:\\develop\\mysql5.7.21\\mysqllog\\mysqld.pid

log-error=H:\\develop\\mysql5.7.21\\mysqllog\\mysql01.err

log-bin=H:\\develop\\mysql5.7.21\\mysqllog\\mysql01-bin

slow-query-log=1

long-query-time=2

slow-query-log-file=H:\\develop\\mysql5.7.21\\mysqllog\\mysql01-slow.log

socket=H:\\develop\\mysql5.7.21\\mysqllog\\mysql.sock

relay-log=H:\\develop\\mysql5.7.21\\mysqllog\\mysql01-relay-bin

 

 

\#### replication configure

server-id = 1

replicate-wild-ignore-table = mysql.%

replicate-wild-ignore-table = information\_schema.%

replicate-wild-ignore-table = performance\_schema.%

replicate-wild-ignore-table = sys.%

binlog-format=ROW

binlog-row-image=full

binlog-rows-query-log-events=1

sync\_binlog=1

log-slave-updates=true

gtid-mode=on

enforce-gtid-consistency=true

 

 

\#### time configure

explicit\_defaults\_for\_timestamp=true

 

 

\# \[client]

#socket=H:\\develop\\mysql5.7.21\\mysqllog\\mysql.sock

 

5、命令行运行

H:\\&gt;mysqld --initialize --basedir=H:\\develop\\mysql5.7.21 --datadir=H:\\develop\\mysql5.7.21\\data

 

H:\\&gt;mysqld --install

Service successfully installed.

 

H:\\&gt;net start mysql

MySQL 服务正在启动 .

MySQL 服务已经启动成功。

 

6、在H:\\develop\\mysql5.7.21\\mysqllog\\mysql01.err 日志中找到

2018-06-15T01:57:06.631815Z 1 \[Note] A temporary password is generated for root@localhost: Ha)w-V0&P5ta

初始密码

 

7、登录mysql

H:\\&gt;mysql -u root -p"Ha)w-V0&P5ta"

mysql: \[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 2

Server version: 5.7.21-log

 

Copyright (c) 2000, 2018, 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&gt; SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password8');

Query OK, 0 rows affected, 1 warning (0.04 sec)

 

mysql&gt; flush privileges;

Query OK, 0 rows affected (0.04 sec)

 

mysql&gt; exit;

Bye

 

**再用新密码登录并显示数据库；**

H:\\&gt;mysql -u root -p

Enter password: \*\*\*\*\*\*\*\**

Welcome to the MySQL monitor.  Commands end with ; or \\g.

Your MySQL connection id is 3

Server version: 5.7.21-log MySQL Community Server (GPL)

 

Copyright (c) 2000, 2018, 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&gt; show databases;

+--------------------+

| Database           |

+--------------------+

| information\_schema |

| mysql              |

| performance\_schema |

| sys                |

+--------------------+

4 rows in set (0.00 sec)

 

mysql&gt;

 

 

 

create database workbook default character set utf8 collate utf8\_general\_ci;

create database workbook default character set utf8mb4 collate utf8mb4\_general\_ci;

#以上命令是创建数据库 workbook ，设置字符集和排序；

 

create user workbook@'%' identified by 'password8';

#创建用户 workbook@'%'， 因mysql是 用户名+主机名 才是完整的用户名；

 

grant all privileges on workbook.* to workbook@'%';

#给用户workbook@'%' 赋所有权限

grant select on workreport.* to workbook@'%';

#给用户workbook@'%' 读取权限

grant replication client on \*.* to workbook@'%';

#给用户workbook@'%' 赋主从复制权限

flush privileges;