Windows10安装MySQL5.7
环境
操作系统:windows10 专业增强版
MySQL:mysql-5.7.24-winx64 下载链接
安装步骤
下载MySQL
选择合适的操作系统版本下载MySQL安装包并解压放置到合适的路径下,例如E:\MySQL路径下
配置系统环境变量
新增MYSQL变量
修改Path变量值
安装MySQL
- 右击开始菜单按钮,选择“命令提示符(管理员)”选项。
- 进入MySQL安装包跟目录的bin路径下,如图所示,执行安装命令
mysqld -install
配置my.ini文件
注意: 安装包里面如果没有my.ini文件,需要自己在MySQL安装路径的根目录下创建
my.ini文件内容如下:
[client]
# pipe=
# socket=MYSQL
default-character-set=utf8
port=3306
[mysql]
no-beep
default-character-set=utf8
# 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.
#
# server_type=3
[mysqld]
# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking
# enable-named-pipe
# shared-memory
# shared-memory-base-name=MYSQL
# The Pipe the MySQL Server will use
# socket=MYSQL
# The TCP/IP Port the MySQL Server will listen on
port=3306
# Path to installation directory. All paths are usually resolved relative to this.
basedir=E:/MySQL/mysql-5.7.24-winx64
# Path to the database root
# The default character set that will be used when a new schema or table is
# created and no character set is defined
character-set-server=utf8
# The default storage engine that will be used when create new tables when
default-storage-engine=INNODB
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# General and Slow logging.
log-output=FILE
general-log=0
general_log_file="mysql57.log"
slow-query-log=1
slow_query_log_file="mysql57-slow.log"
long_query_time=10
# Binary Logging.
# log-bin
# Error Logging.
log-error="mysql57.err"
# Server Id.
server-id=1
# Specifies the on how table names are stored in the metadata.
# If set to 0, will throw an error on case-insensitive operative systems
# If set to 1, table names are stored in lowercase on disk and comparisons are not case sensitive.
# If set to 2, table names are stored as given but compared in lowercase.
# This option also applies to database names and table aliases.
lower_case_table_names=1
# The maximum amount of concurrent sessions the MySQL server will
# allow. One of these connections will be reserved for a user with
# SUPER privileges to allow the administrator to login even if the
# connection limit has been reached.
max_connections=151
说明
- 编码改为utf8
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
- 注意log-error的值(mysql57.err),下面步骤中需要从中获取登录的初始密码
初始化MySQL
在刚才的“命令提示符”中,执行mysqld --initialize
启动MySQL
执行net start mysql
进入MySQL
- 进入安装跟目录的data路径中,找到mysql57.err文件,打开搜索
A temporary password is generated for [email protected]:
紧跟在后面的就是初始密码(oGkoF:sQe9lf)
- 执行命令
mysql -uroot -p
输入上面的初始密码登录
- 修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
- 查看是否为utf8编码
show variables like 'character%';
- root用户授权
GRANT ALL PRIVILEGES ON *.* TO [email protected]'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
- 刷新退出
flush privileges;
exit!
注意事项
1、彻底删除MySQL, 参考
2、utf8_general_ci和utf8_unicode_ci区别 参考
3、一定要以"管理员模式"打开"命令提示符"
参考链接
1、https://blog.csdn.net/yulutian/article/details/78971369
2、https://www.jianshu.com/p/710e5861c198