mysql5.7 zip windows下安装

来源:互联网 发布:网络用语der什么意思 编辑:程序博客网 时间:2024/05/21 10:33

今天安装mysql5.7.10的zip windows版发现不少问题,记录一下

首先下载mysql  http://dev.mysql.com/downloads/mysql/

解压到D:\Program Files\mysql-5.7.10-winx64

并将该目录添加到环境变量path中

在该目录下复制my-default.ini中的内容,新建一个文件my.ini,并将内容粘贴进去。

现在该目录的结构为


修改my.ini的内容如下

# For advice on how to change settingsplease see

#http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

# *** DO NOT EDIT THIS FILE. It's atemplate which will be copied to the

# *** default location during install, andwill be replaced if you

# *** upgrade to a newer version of MySQL.

[mysql]

default-character-set=utf8

[mysqld]

 

# Remove leading # and set to the amount ofRAM for the most important data

# cache in MySQL. Start at 70% of total RAMfor dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

 

# Remove leading # to turn on a veryimportant data integrity option: logging

# changes to the binary log betweenbackups.

# log_bin

 

# These are commonly set, remove the # andset as required.

basedir = D:/Program Files/mysql-5.7.10-winx64

datadir = D:/Program Files/mysql-5.7.10-winx64/data

port = 3306

# server_id = .....

character_set_server=utf8

 

 

# Remove leading # to set options mainlyuseful for reporting servers.

# The server defaults are faster fortransactions and fast SELECTs.

# Adjust sizes as needed, experiment tofind the optimal values.

# join_buffer_size = 128M

# sort_buffer_size = 2M

# read_rnd_buffer_size = 2M

 

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[client]

port=3306

default-character-set=utf8

之后打开cmd命令窗口,注意要以管理员的身份运行,

转到D:\Program Files\mysql-5.7.10-winx64目录中执行

mysqld –install

将mysql安装为服务

之后启动服务

net start mysql

发现服务无法启动,在网上查找问题和参考官方文档,http://dev.mysql.com/doc/refman/5.7/en/data-directory-initialization-mysqld.html,发现需要手工的创建data文件夹

运行命令

mysqld –initialize

会卡顿一会儿,之后会看到D:\Program Files\mysql-5.7.10-winx64目录中会出现一个data文件夹

接着启动服务

net start mysql

服务成功启动

之后修改mysql的root密码,

执行

mysql –u root

发现无法登陆

查看官方文档

有以下说明

To initialize the data directory, invokemysqld with the --initialize or --initialize-insecure option, depending onwhether you want the server to generate a random initial password for the'root'@'localhost' account.

Regardless of platform, use --initializefor “secure by default” installation (that is, including generation of a randominitial root password). In this case, the password is marked as expired and youwill need to choose a new one. With the --initialize-insecure option, no rootpassword is generated; it is assumed that you will assign a password to theaccount in timely fashion before putting the server into production use.

大概意思是以—initialize创建的data文件夹会为root @ localhost生成一个随机的密码,以--initialize-insecure不会创建密码

笔者使用的是—initialize,继续查看文档

With --initialize but not--initialize-insecure, the server generates a random password, marks it asexpired, and writes a message displaying the password:

 

[Warning] A temporary password is generated for root@localhost:

iTag*AfrH5ej

If you used --initialize but not --initialize-insecure to initializethe data directory, connect to the server as root using the random passwordthat the server generated during the initialization sequence:

 

shell> mysql -u root -p

Enter password: (enter the random rootpassword here)

Look in the server error log if you do not know this password.

 

If you used --initialize-insecure toinitialize the data directory, connect to the server as root without apassword:

 

shell> mysql -u root --skip-password

大概意思是说以—initialize方式创建data时要以mysql -u root –p命令登陆,并且密码不知道的话会在错误日志中,

回到D:\Program Files\mysql-5.7.10-winx64中,进入data文件夹,看到一个以当前的计算机名为名字,以.err为后缀的文件,打开,如下图


在第8行发现了临时随机生成的密码,47rhFKYdyC/k

执行命令mysql -u root –p

输入密码47rhFKYdyC/k

成功登陆

运行语句

ALTER USER 'root'@'localhost' IDENTIFIED BY'new_password';

更改root密码。

0 0