您的位置:首页 > 数据库 > MySQL

mysql5.7.10 zip windows安装

2015-12-26 21:55 821 查看
从该网址下载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 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.
[mysql]

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.
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 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

[client]

port=3306

default-character-set=utf8

之后保存文件,打开cmd命令行窗口,注意已管理员身份运行,进入mysql的目录,即D:\Program Files\mysql-5.7.10-winx64

执行以下命令

mysqld  -install

将mysql安装为服务

接着启动服务

net start mysql

此时出错

在网上查看资料,以及参考mysql官方文档点击打开链接,需要初始化手动初始化data文件夹

命令为

mysqld --initialize

之后再执行

net start mysql

服务顺利启动

之后需要修改root的密码

输入命令mysql -u root

报错  说 root@localhost 有密码,需要密码才能登录

问题出在了手动初始化data文件夹To initialize the data directory, invoke mysqld with the --initialize or --initialize-insecure option, depending on whether you want the server to generate a random initial password for the 'root'@'localhost' account.

官方 文档说

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

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

大概意思是采用 --initialize 和 --initialize-insecure两种方式生成data文件夹,但是--initalize会随机生成一个密码分配给root@localhost,而--initialize-insecure不会生成密码,我使用了--initialize,继续查看文档

Connect to the server:

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

shell> mysql -u root -p

Enter password: (enter the random root password here)
Look in the server error log if you do not know this password.

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

shell> mysql -u root --skip-password

可以在error日志文件中找到,到D:\Program Files\mysql-5.7.10-winx64中的data文件夹下,发现一个以自己计算机名称为名,以.err为后缀的文件,打开



发现在第8行有一个临时密码被生成为47rhFKYdyC/k

重新登录

mysql -u root -p

输入密码 47rhFKYdyC/k

顺利登录

修改root密码

set password for root@localhost password("新密码")

或者采用命令

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';修改命令

即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息