【MySQL】windows安装MySQL 5.7
如果直接安装官网的安装包(MySQL Community Server),会连带一些用不上的软件。
一、下载MySQL
清华大学开源软件镜像站:mysql-5.7.31-winx64.msi
二、安装MySQL
可以用ZIP,也可以用安装包,个人感觉安装包更容易管理。
双击安装,默认路径:C:\Program Files\MySQL\MySQL Server 5.7
安装后大约占用400MB空间,实际数据本身也会占一定空间。
三、添加环境变量
四、创建文件夹
安装成功后,系统会新增两个文件夹。
- C:\Program Files\MySQL\MySQL Server 5.7
- C:\ProgramData\MySQL\MySQL Server 5.7\data
但是data文件夹是空的(里面有三个文件夹,也是空的)。
假如data有内容,把data全部内容删除,然后用命令行初始化。
Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。
PS C:\Windows\system32> cd 'C:\Program Files\MySQL\MySQL Server 5.7\bin\'
PS C:\Program Files\MySQL\MySQL Server 5.7\bin> .\mysqld.exe --initialize-insecure --user=mysql --datadir="C:\ProgramData\MySQL\MySQL Server 5.7\data"
PS C:\Program Files\MySQL\MySQL Server 5.7\bin>
五、配置文件
配置文件优先级
- C:\Windows\my.ini
- C:\Windows\my.cnf
- C:\my.ini
- C:\my.cnf
- C:\Program Files\MySQL\MySQL Server 5.7\my.ini
- C:\Program Files\MySQL\MySQL Server 5.7\my.cnf
客户端配置
路径:C:\Program Files\MySQL\MySQL Server 5.7\my.ini
[mysql]
no-beep
default-character-set=utf8
服务端配置
路径:C:\ProgramData\MySQL\MySQL Server 5.7\data\my.ini
[mysqld]
# Path to installation directory. All paths are usually resolved relative to this.
basedir="C:/Program Files/MySQL/MySQL Server 5.7/"
# Path to the database root
datadir="C:/ProgramData/MySQL/MySQL Server 5.7/data/"
# The TCP/IP Port the MySQL Server will listen on
port=3306
# sql_mode
sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
# UTF-8
character_set_server=utf8
# innoDB
default-storage-engine=INNODB
# ***** Group Replication Related *****
# Defines the algorithm used to hash the writes extracted during a transaction. If you
# are using Group Replication, this variable must be set to XXHASH64 because the process
# of extracting the writes from a transaction is required for conflict detection on all
# group members.
# transaction_write_set_extraction
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
# The number of open tables for all threads. Increasing this value
# increases the number of file descriptors that mysqld requires.
# Therefore you have to make sure to set the amount of open files
# allowed to at least 4096 in the variable "open-files-limit" in
# section [mysqld_safe]
table_open_cache=2000
# Maximum size for internal (in-memory) temporary tables. If a table
# grows larger than this value, it is automatically converted to disk
# based table This limitation is for a single table. There can be many
# of them.
tmp_table_size=19M
# How many threads we should keep in a cache for reuse. When a client
# disconnects, the client's threads are put in the cache if there aren't
# more than thread_cache_size threads from before. This greatly reduces
# the amount of thread creations n