目录
一、安装准备
1.1 下载
1.2 版本说明
二、安装步骤
2.1 解压缩
2.2 配置环境变量
2.3 配置文件
2.4 安装
2.5 启动/停止服务
三、使用说明
3.1 用户名密码登录
3.1 设置用户名密码
四、卸载步骤
4.1 卸载服务
五、安装问题
六、启动问题
6.1 提示【服务无法启动】
6.1.1 问题描述
6.1.2 解决方案
一、安装准备
1.1 下载
1、MySQL官网地址MySQLhttps://www.mysql.com/
2、点击【DOWNLOAD】菜单。
往下翻,点击【MySQL Community (GPL) Downloads】连接。
选择【MySQL Community Server】选项,下载MySQL。
1.2 版本说明
本文档编写时,使用的是8.0.26-win64的解压缩版本。
二、安装步骤
2.1 解压缩
将压缩包解压缩到目标目录。
2.2 配置环境变量
1、【我的电脑/此电脑】右键,点击【属性】,选择【高级系统配置】
2、点击【环境变量】,在弹出框中,选择新建【系统变量】。
变量名建议为:MYSQL_HOME;变量值为MySQL的解压路径;
3、在【系统变量】中找到Path变量,并新增MYSQL的环境变量。
2.3 配置文件
将如下内容拷贝到名为my.ini的文件中,并将其放入到解压根目录中。
其中,较为重要的配置为:
# 设置mysql客户端连接服务端时默认使用的端口;
port=3306
# 设置mysql的安装目录;
basedir="D:\mysql\"
# 设置mysql数据库的数据的存放目录;
datadir="D:\mysql\data"
# MySQL Server Instance Configuration File
# ----------------------------------------------------------------------
# Generated by the MySQL Server Instance Configuration Wizard
#
#
# Installation Instructions
# ----------------------------------------------------------------------
#
#
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# 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]# 设置mysql客户端连接服务端时默认使用的端口;
port=3306
# 绑定本地IP;
bind-address = 127.0.0.1
# 客户端默认字符集编码为utf8mb4;
default-character-set=utf8mb4[mysql]
# MySQL默认字符集编码为utf8mb4;
default-character-set=utf8mb4# 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]# The TCP/IP Port the MySQL Server will listen on
# 设置默认端口为3306;
port=3306
# 绑定本地IP;
bind-address = 127.0.0.1#Path to installation directory. All paths are usually resolved relative to this.
# 设置mysql的安装目录;
basedir="D:\mysql\"
#Path to the database root
# 设置mysql数据库的数据的存放目录;
datadir="D:\mysql\data"
[WinMySQLadmin]
# mysqld服务路径;
Server="D:\mysql\bin\mysqld.exe"# The default character set that will be used when a new schema or table is
# created and no character set is defined
# 服务端默认字符集编码为utf8mb4;
default-character-set=utf8mb4# 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"# 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=100# Query cache is used to cache SELECT results and later return them
# without actual executing the same query once again. Having the query
# cache enabled may result in significant speed improvements, if your
# have a lot of identical queries and rarely changing tables. See the
# "Qcache_lowmem_prunes" status variable to check if the current value
# is high enough for your load.
# Note: In case your tables change very often or if your queries are
# textually different every time, the query cache may result in a
# slowdown instead of a performance improvement.
# 查询缓存大小;
query_cache_size=0# 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_cache=256# 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=26M
# 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 needed if you have a lot of new
# connections. (Normally this doesn't give a notable performance
# improvement if you have a good thread implementation.)
# 线程数;
thread_cache_size=8#*** MyISAM Specific options
# The maximum size of the temporary file MySQL is allowed to use while
# recreating the index (during REPAIR, ALTER TABLE or LOAD DATA INFILE.
# If the file-size would be bigger than this, the index will be created
# through the key cache (which is slower).
myisam_max_sort_file_size=100G# If the temporary file used for fast index creation would be bigger
# than using the key cache by the amount specified here, then prefer the
# key cache method. This is mainly used to force long character keys in
# large tables to use the slower key cache method to create the index.
myisam_sort_buffer_size=52M# Size of the Key Buffer, used to cache index blocks for MyISAM tables.
# Do not set it larger than 30% of your available memory, as some memory
# is also required by the OS to cache rows. Even if you're not using
# MyISAM tables, you should still set it to 8-64M as it will also be
# used for internal temporary disk tables.
key_buffer_size=40M# Size of the buffer used for doing full table scans of MyISAM tables.
# Allocated per thread, if a full scan is needed.
read_buffer_size=64K
read_rnd_buffer_size=256K# This buffer is allocated when MySQL needs to rebuild the index in
# REPAIR, OPTIMZE, ALTER table statements as well as in LOAD DATA INFILE
# into an empty table. It is allocated per thread so be careful with
# large settings.
sort_buffer_size=256K
#*** INNODB Specific options ***
# INNODB的数据存放目录;
innodb_data_home_dir="D:\mysql\data\INNODB\"# Use this option if you have a MySQL server with InnoDB support enabled
# but you do not plan to use it. This will save memory and disk space
# and speed up some things.
#skip-innodb# Additional memory pool that is used by InnoDB to store metadata
# information. If InnoDB requires more memory for this purpose it will
# start to allocate it from the OS. As this is fast enough on most
# recent operating systems, you normally do not need to change this
# value. SHOW INNODB STATUS will display the current amount used.
innodb_additional_mem_pool_size=2M# If set to 1, InnoDB will flush (fsync) the transaction logs to the
# disk at each commit, which offers full ACID behavior. If you are
# willing to compromise this safety, and you are running small
# transactions, you may set this to 0 or 2 to reduce disk I/O to the
# logs. Value 0 means that the log is only written to the log file and
# the log file flushed to disk approximately once per second. Value 2
# means the log is written to the log file at each commit, but the log
# file is only flushed to disk approximately once per second.
innodb_flush_log_at_trx_commit=1# The size of the buffer InnoDB uses for buffering log data. As soon as
# it is full, InnoDB will have to flush it to disk. As it is flushed
# once per second anyway, it does not make sense to have it very large
# (even with long transactions).
innodb_log_buffer_size=1M# InnoDB, unlike MyISAM, uses a buffer pool to cache both indexes and
# row data. The bigger you set this the less disk I/O is needed to
# access data in tables. On a dedicated database server you may set this
# parameter up to 80% of the machine physical memory size. Do not set it
# too large, though, because competition of the physical memory may
# cause paging in the operating system. Note that on 32bit systems you
# might be limited to 2-3.5G of user level memory per process, so do not
# set it too high.
innodb_buffer_pool_size=77M# Size of each log file in a log group. You should set the combined size
# of log files to about 25%-100% of your buffer pool size to avoid
# unneeded buffer pool flush activity on log file overwrite. However,
# note that a larger logfile size will increase the time needed for the
# recovery process.
innodb_log_file_size=39M# Number of threads allowed inside the InnoDB kernel. The optimal value
# depends highly on the application, hardware as well as the OS
# scheduler properties. A too high value may lead to thread thrashing.
innodb_thread_concurrency=8
2.4 安装
1、使用管理员权限运行CMD(此处省略使用管理员运行CMD的方法)。
2、使用盘符 + : 的形式,切换到目标盘符。
3、使用CD切换到目标路径下。目标路径为解压缩目录\bin。
4、运行mysqld install mysql --defaults-file="d:\mysql\my.ini"命令。
2.5 启动/停止服务
运行net start mysql命令,服务启动成功。
运行net stop mysql命令,服务停止成功。
三、使用说明
3.1 用户名密码登录
服务初始化好后,会默认配置用户名和密码;
A temporary password is generated for root@localhost: ******;
输入mysql命令进行登录,-h代表IP地址,-u代表用户名,-p代表密码;
3.1 设置用户名密码
登录后,执行命令:ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';,修改密码完成;
四、卸载步骤
4.1 卸载服务
执行mysqld remove命令,卸载服务。
五、安装问题
暂无;
六、启动问题
6.1 提示【服务无法启动】
6.1.1 问题描述
如图所示,提示服务无法启动。
6.1.2 解决方案
根据2.3的配置,datadir="D:\mysql\data" 可知,在解压缩目录下的data目录中,存放有数据库相关文件。
情况一:
如果是手动创建了data目录,则进入目录后,可以看到后缀名为.err的文件,打开文件可以看到启动报错信息。
报错说明初始化data目录失败。因此需要删除data目录,由mysql自己初始化data目录,此时重新尝试即可。
情况二:
如果使用mysqld install命令安装时,未初始化data目录,则说明安装“失败”了,启动时一定会报错。
此时需要使用mysqld --initialize --console命令,初始化MySQL。
初始化后,再执行mysqld install mysql --defaults-file="d:\mysql\my.ini"安装命令。
此时,服务启动成功,可以正常使用。