一、具体安装过程
-
将下载的 MySQL Server 5.7 解压至需要安装的位置, 如: C:\Program Files;如下图所示:
2.修改环境变量
新建MYSQL_HOME环境变量
MYSQL_HOME=C:\Program Files\MySQL\MySQL Server 5.7
路径为你的mysql安装路径,如图所示:
在path环境变量中添加参数
3.修改mysql配置文件
在mysql安装路径下,复制一份my-default.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.
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
[client]
default-character-set = utf8
port=3306
[mysql]
default-character-set = utf8
参数意义:
上面显示的是客户端的参数,client]和[mysql]都是客户端,下面是参数简介:
1.port参数表示的是MySQL数据库的端口,默认的端口是3306,如果你需要更改端口号的话,就可以通过在这里修改。
2.default-character-set参数是客户端默认的字符集,如果你希望它支持中文,可以设置成gbk或者utf8。
3.这里还有一个password参数,在这里设置了password参数的值就可以在登陆时不用输入密码直接进入。
# SERVER SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by the MySQL Server. Make sure that
# you have installed the server correctly (see above) so it reads this
# file.
#
[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.
# 设置mysql的安装目录
basedir = C:/Program Files/MySQL/MySQL Server 5.7
# 设置mysql数据库的数据的存放目录
datadir = C:/Program Files\MySQL/MySQL Server 5.7/data
#设置mysql数据库3306端口 The TCP/IP Port the MySQL Server will listen on
port = 3306
# 服务端使用的字符集默认为8比特编码的latin1字符集
character_set_server = utf8
# server_id = .....
# 允许最大连接数
max_connections=200
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 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
上面是服务器断参数,一下是参数的简介:
1.port参数也是表示数据库的端口。
2.basedir参数表示MySQL的安装路径。
3.datadir参数表示MySQL数据文件的存储位置,也是数据库表的存放位置。
4.default-character-set参数表示默认的字符集,这个字符集是服务器端的。
5.default-storage-engine参数默认的存储引擎。
6.sql-mode参数表示SQL模式的参数,通过这个参数可以设置检验SQL语句的严格程度。
7.max_connections参数表示允许同时访问MySQL服务器的最大连接数,其中一个连接是保留的,留给管理员专用的。
注意路径中为/或者\而非\
二、启动mysql
1、以管理员的方式打开cmd命令窗口,(因为已经配置了环境变量,无需进入mysql安装路径)
查看mysql版本信息:
mysql --version
如果出错或者显示没有mysql这个命令,一般是环境变量设置错误。
2、安装 MySQL 服务,
执行命令:
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --install MySQL60 --defaults-file="C:\Program Files\MySQL\MySQL Server 5.7\my.ini"
提示"Service successfully installed."表示成功;
此时在windows 服务中可以看到mysql已经成为windows的一个服务。

同时在注册中心可以看到如下信息:
地址:
计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MySQL60
3、启动mysql60
执行命令:
net start mysql60
4、连接数据库
执行命令:
mysql -uroot -p
mysql -h 主机名 -u 用户名 -p
-h : 该命令用于指定客户端所要登录的MySQL主机名, 登录当前机器该参数可以省略;
-u : 所要登录的用户名;
-p : 告诉服务器将会使用一个密码来登录, 如果所要登录的用户名密码为空, 可以忽略此选项。
5、停止mysql
执行命令:
net stop mysql60
三、遇到的问题
1、数据库密码不正确,报错
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
12.PNG
解决方案1:在配置文件my.ini中[mysqld]块中加入skip-grant-tables
[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
skip-grant-tables
# These are commonly set, remove the # and set as required.
# 设置mysql的安装目录
basedir = C:/Program Files/MySQL/MySQL Server 5.7
再次登录时,不需要输入密码,直接回车即可。
解决方案2:在mysql5.7中,用户第一次登录系统,会在mysql错误日志中显示密码
输入密码,即可。之后可以自行修改密码,相关命令如下
use mysql;
update mysql.user set authentication_string=password('123456') where user='root' and Host = 'localhost';
flush privileges;
flush privileges:告诉mysql刷新一下系统权限,此时修改的密码才会生效。重启mysql。
5.7以后password字段不在存在,变成了authentication_string,否则
会报如下错误:ERROR 1054 (42S22): Unknown column 'password' in 'field list'
2系统日志文件时间不对
2018-09-15T17:50:50.682657Z 0 [Note] Giving 0 client threads a chance to die gracefully
2018-09-15T17:50:50.683655Z 0 [Note] Shutting down slave threads
2018-09-15T17:50:50.683655Z 0 [Note] Forcefully disconnecting 0 remaining clients
2018-09-15T17:50:50.683655Z 0 [Note] Event Scheduler: Purging the queue. 0 events
2018-09-15T17:50:50.684666Z 0 [Note] Binlog end
14.PNG
解决方案:5.7.2后,MySQL加入了一个参数,log_timestamps,这个参数是用于控制error log、general log、slow log日期时区的。这个参数最坑爹的地方是,默认值为"UTC",UTC为世界协调时间
将时间设为本地时间
SET GLOBAL log_timestamps=SYSTEM; SELECT @@log_timestamps;
网友评论