windows mysql no install 配置_mysql在windows下的安装和配置

1.  windows下安装mysql,有两种方式:

第一种,使用msi后缀的文件安装。

https://dev.mysql.com/downloads/file/?id=474803

这种方式安装简单,配置简单,点击下一步完成即可。我们生产使用的版本是mysql5.1,现在新下载的是mysql5.7。

这种方式只有32bit,但是它的二进制文件有32bit和64bit。

第二种,使用源码的方式。

这种方式免安装。https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.21-winx64.zip

下载解压缩到指定的目录下。

1.  把mysql的bin目录添加到系统环境变量。

添加到PATH的最后。

2.  执行mysqld初始化

启动mysqld,结果报错:

C:\Users\yangjianbo>mysqld

mysqld: Can't change dir to 'F:\mysql-5.7.20-win32\data\' (Errcode: 2 - No such

file or directory)

2017-12-02T03:34:27.606962Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is

deprecated. Please use --explicit_defaults_for_timestamp server option (see doc

umentation for more details).

2017-12-02T03:34:27.607962Z 0 [Note] --secure-file-priv is set to NULL. Operatio

ns related to importing and exporting data are disabled

2017-12-02T03:34:27.607962Z 0 [Note] mysqld (mysqld 5.7.20) starting as process

4344 ...

2017-12-02T03:34:27.611962Z 0 [Warning] Can't create test file F:\mysql-5.7.20-w

in32\data\yangjianbo-PC.lower-test

2017-12-02T03:34:27.612962Z 0 [Warning] Can't create test file F:\mysql-5.7.20-w

in32\data\yangjianbo-PC.lower-test

2017-12-02T03:34:27.612962Z 0 [ERROR] failed to set datadir to F:\mysql-5.7.20-w

in32\data\

2017-12-02T03:34:27.613963Z 0 [ERROR] Aborting

2017-12-02T03:34:27.613963Z 0 [Note] Binlog end

2017-12-02T03:34:27.613963Z 0 [Note] mysqld: Shutdown complete

解决方法:

因为我下载的是mysql5.7版本,默认没有data目录。

需要初始化一下,才能生成data目录。

mysqld --initialize-insecure --user=mysql   (mysql5.7必须初始化,不然无法使用my.ini文件)

会自动创建一个data目录

然后执行mysqld,就把mysql服务启动了。

这样虽然mysqld可以起来,但是我希望还是自己定制一些参数,所以还需要my.ini文件,需要在F:\mysql-5.7.21-winx64目录下创建my.ini文件,并添加内容。

3.  在F:\mysql-5.7.21-winx64目录下创建my.ini文件,内容如下:

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8

[mysqld]

#设置3306端口

port = 3306

# 设置mysql的安装目录

basedir=F:\mysql-5.7.21-winx64

# 设置mysql数据库的数据的存放目录

datadir=F:\mysql-5.7.21-winx64\data

# 允许最大连接数

max_connections=200

# 服务端使用的字符集默认为8比特编码的latin1字符集

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

4.  新建my.ini以后,必须重新初始化一下,才能生效。

mysqld --initialize-insecure --user=mysql

结果报错:

C:\Users\Administrator>mysqld --initialize-insecure --user=mysql

2018-03-20T01:00:28.328113Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is

deprecated. Please use --explicit_defaults_for_timestamp server option (see doc

umentation for more details).

2018-03-20T01:00:28.328113Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E

RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will

be merged with strict mode in a future release.

2018-03-20T01:00:28.328113Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not s

et.

2018-03-20T01:00:28.332113Z 0 [ERROR] --initialize specified but the data direct

ory has files in it. Aborting.

2018-03-20T01:00:28.335113Z 0 [ERROR] Aborting

解决方法:

在my.ini中添加一句:explicit_defaults_for_timestamp=true

然后还有报错,如下:

C:\Users\Administrator>mysqld --initialize-insecure --user=mysql

2018-03-20T01:08:45.122528Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'E

RROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will

be merged with strict mode in a future release.

2018-03-20T01:08:45.122528Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not s

et.

2018-03-20T01:08:45.126528Z 0 [ERROR] --initialize specified but the data direct

ory has files in it. Aborting.

2018-03-20T01:08:45.129528Z 0 [ERROR] Aborting

把data目录下的文件清空,重新执行一下初始化。问题解决。

5.  把mysql添加为系统服务。

进入F:\mysql-5.7.21-winx64\bin目录下, 然后执行mysqld  --install

6.  Mysql5.6就不需要进行初始化。直接mysqld启动即可。

7.  为管理员root设置密码。

update mysql.user set authentication_string=password('SanMu@DaShu') where user='root';

flush privileges;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值