Windows10系统 MySQL数据库安装

追求适度,才能走向成功;人在顶峰,迈步就是下坡;身在低谷,抬足既是登高;弦,绷得太紧会断;人,思虑过度会疯;水至清无鱼,人至真无友,山至高无树;适度,不是中庸,而是一种明智的生活态度。

导读:本篇文章讲解 Windows10系统 MySQL数据库安装,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

目录

一、下载MySQL安装包

二、配置环境变量

三、my.ini配置

四、cmd指令安装MySQL数据库


一、下载MySQL安装包

官网下载地址:mysql社区版

下载红线圈起来的哪项:

Windows10系统 MySQL数据库安装

下载后解压,把解压包mysql-8.0.26-winx64复制到你觉得舒服的盘。 

二、配置环境变量

1、右键桌面的此电脑  > 找到高级系统设置 > 进入最下面环境变量(N)…> 找到系统变量选项框 点击Path再点击编辑 > 点击新建然后点击浏览找到你复制的解压包打开到bin文件夹 最后确定。

2、或者在控制面板找到系统  > 找到高级系统设置 > 进入最下面环境变量(N)…> 找到系统变量选项框 点击Path再点击编辑 > 点击新建然后点击浏览找到你复制的解压包打开到bin文件夹 最后确定。

提示:x:\xxxx\xxxx\bin

三、my.ini配置

常见的配置:

[mysql]

# 设置mysql客户端默认字符集

default-character-set=utf8


[mysqld]

# 设置3306端口

port = 3306

# 设置mysql的安装目录

basedir=E:\\mysql-8.0.26-winx64\\bin

# 设置 mysql数据库的数据的存放目录,MySQL 8+ 不需要以下配置,系统自己生成即可,否则有可能报错

datadir=E:\\mysql-8.0.26-winx64\\data

# 允许最大连接数

max_connections=1000

# 服务端使用的字符集默认utf8

character-set-server=utf8

# 创建新表时将使用的默认存储引擎

default-storage-engine=INNODB

提示:复杂的配置如下

1、配置文件说明信息。

# CLIENT SECTION
# ----------------------------------------------------------------------
[client]
#password =1234 

# pipe
# socket=mysql
# 设置mysql客户端连接服务端时默认使用的端口
port=3306

default-character-set=utf8
[mysql]
port=3306
# 设置mysql客户端默认字符集
default-character-set=utf8


# SERVER SECTION
# ----------------------------------------------------------------------
[mysqld]
# mysql服务端默认监听(listen on)的TCP/IP端口
port=3306

# 基准路径,其他路径都相对于这个路径;即MySQL的安装路径
basedir="D:\MySQL"

# mysql数据库文件所在目录
datadir="D:\Mysql\data"

# 服务端使用的字符集默认为8比特编码的utf-8字符集
character-set-server=utf8

# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB

# SQL模式为strict模式
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

# General and Slow logging.
log-output=NONE
general-log=0
general_log_file="WANGZHANGJIE.log"
slow-query-log=0
slow_query_log_file="WANGZHANGJIE-slow.log"
long_query_time=10

# Error Logging.
log-error="WANGZHANGJIE.err"

# mysql服务器支持的最大并发连接数(用户数)。但总会预留其中的一个连接给管理员使用超级权限登录,
# 即使连接数目达到最大限制。如果设置得过小而用户比较多,会经常出现“Too many connections”错误。
max_connections=100

# 查询缓存大小,用于缓存SELECT查询结果。如果有许多返回相同查询结果的SELECT查询,并且很少改变表,
# 可以设置query_cache_size大于0,可以极大改善查询效率。而如果表数据频繁变化,就不要使用这个,会适得其反
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_open_cache=2000

# 内存中的每个临时表允许的最大大小。如果临时表大小超过该值,临时表将自动转为基于磁盘的表(Disk Based Table)。
tmp_table_size=20M

# 缓存的最大线程数。当客户端连接断开时,如果客户端总连接数小于该值,则处理客户端任务的线程放回缓存。
# 在高并发情况下,如果该值设置得太小,就会有很多线程频繁创建,
# 线程创建的开销会变大,查询效率也会下降。一般来说如果在应用端有良好的多线程处理,这个参数对性能不会有太大的提高。
thread_cache_size=9

# mysql重建索引时允许使用的临时文件最大大小
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=39M


# Key Buffer大小,用于缓存MyISAM表的索引块。决定数据库索引处理的速度(尤其是索引读)
key_buffer_size=8M


# 用于对MyISAM表全表扫描时使用的缓冲区大小。针对每个线程进行分配(前提是进行了全表扫描)。
# 进行排序查询时,MySql会首先扫描一遍该缓冲,以避免磁盘搜索,提高查询速度,
# 如果需要排序大量数据,可适当调高该值。但MySql会为每个客户连接发放该缓冲空间,
# 所以应尽量适当设置该值,以避免内存开销过大。
read_buffer_size=64K
read_rnd_buffer_size=256K


# connection级参数(为每个线程配置),500个线程将消耗500*256K的sort_buffer_size。
sort_buffer_size=256K


# InnoDB用于存储元数据信息的内存池大小,一般不需修改
innodb_additional_mem_pool_size=2M


# 事务相关参数,如果值为1,则InnoDB在每次commit都会将事务日志写入磁盘(磁盘IO消耗较大),
# 这样保证了完全的ACID特性。而如果设置为0,则表示事务日志写入内存log和内存log写入磁盘的频率都为1次/秒。
# 如果设为2则表示事务日志在每次commit都写入内存log,但内存log写入磁盘的频率为1次/秒。


innodb_flush_log_at_trx_commit=1


# InnoDB日志数据缓冲大小,如果缓冲满了,就会将缓冲中的日志数据写入磁盘(flush)。
# 由于一般至少都1秒钟会写一次磁盘,所以没必要设置过大,即使是长事务。
innodb_log_buffer_size=1M

# InnoDB使用缓冲池来缓存索引和行数据。该值设置的越大,则磁盘IO越少。一般将该值设为物理内存的80%。
innodb_buffer_pool_size=97M

# 每一个InnoDB事务日志的大小。一般设为innodb_buffer_pool_size的25%到100%
innodb_log_file_size=48M

# InnoDB内核最大并发线程数
innodb_thread_concurrency=9

# The increment size (in MB) for extending the size of an auto-extend InnoDB system tablespace file when it becomes full.
innodb_autoextend_increment=64M

# The number of regions that the InnoDB buffer pool is divided into.
# For systems with buffer pools in the multi-gigabyte range, dividing the buffer pool into separate instances can improve concurrency,
# by reducing contention as different threads read and write to cached pages.
innodb_buffer_pool_instances=8

# Determines the number of threads that can enter InnoDB concurrently.
innodb_concurrency_tickets=5000

# Specifies how long in milliseconds (ms) a block inserted into the old sublist must stay there after its first access before
# it can be moved to the new sublist.
innodb_old_blocks_time=1000

# It specifies the maximum number of .ibd files that MySQL can keep open at one time. The minimum value is 10.
innodb_open_files=300

# When this variable is enabled, InnoDB updates statistics during metadata statements.
innodb_stats_on_metadata=0

# When innodb_file_per_table is enabled (the default in 5.6.6 and higher), InnoDB stores the data and indexes for each newly created table
# in a separate .ibd file, rather than in the system tablespace.
innodb_file_per_table=1

# Use the following list of values: 0 for crc32, 1 for strict_crc32, 2 for innodb, 3 for strict_innodb, 4 for none, 5 for strict_none.
innodb_checksum_algorithm=0

# The number of outstanding connection requests MySQL can have.
# This option is useful when the main MySQL thread gets many connection requests in a very short time.
# It then takes some time (although very little) for the main thread to check the connection and start a new thread.
# The back_log value indicates how many requests can be stacked during this short time before MySQL momentarily
# stops answering new requests.
# You need to increase this only if you expect a large number of connections in a short period of time.
back_log=70


# If this is set to a nonzero value, all tables are closed every flush_time seconds to free up resources and
# synchronize unflushed data to disk.
# This option is best used only on systems with minimal resources.
flush_time=0

# The minimum size of the buffer that is used for plain index scans, range index scans, and joins that do not use
# indexes and thus perform full table scans.
join_buffer_size=256K

# The maximum size of one packet or any generated or intermediate string, or any parameter sent by the
# mysql_stmt_send_long_data() C API function.
max_allowed_packet=4M

# If more than this many successive connection requests from a host are interrupted without a successful connection,
# the server blocks that host from performing further connections.
max_connect_errors=100

# Changes the number of file descriptors available to mysqld.
# You should try increasing the value of this option if mysqld gives you the error "Too many open files".
open_files_limit=4110

# Set the query cache type. 0 for OFF, 1 for ON and 2 for DEMAND.
query_cache_type=0

# If you see many sort_merge_passes per second in SHOW GLOBAL STATUS output, you can consider increasing the
# sort_buffer_size value to speed up ORDER BY or GROUP BY operations that cannot be improved with query optimization
# or improved indexing.
sort_buffer_size=256K

# The number of table definitions (from .frm files) that can be stored in the definition cache.
# If you use a large number of tables, you can create a large table definition cache to speed up opening of tables.
# The table definition cache takes less space and does not use file descriptors, unlike the normal table cache.
# The minimum and default values are both 400.
table_definition_cache=1400

# Specify the maximum size of a row-based binary log event, in bytes.
# Rows are grouped into events smaller than this size if possible. The value should be a multiple of 256.
binlog_row_event_max_size=8K

# If the value of this variable is greater than 0, a replication slave synchronizes its master.info file to disk.
# (using fdatasync()) after every sync_master_info events.
sync_master_info=10000

# If the value of this variable is greater than 0, the MySQL server synchronizes its relay log to disk.
# (using fdatasync()) after every sync_relay_log writes to the relay log.
sync_relay_log=10000

# If the value of this variable is greater than 0, a replication slave synchronizes its relay-log.info file to disk.
# (using fdatasync()) after every sync_relay_log_info transactions.
sync_relay_log_info=10000

记得在你的解压包下新建my.ini,将上面内容复制进去保存。

四、cmd指令安装MySQL数据库

注意:环境变量和my.ini配置完成后才能进行下列操作

使用管理员模式:

右键左下角的windows10图标,找到Windows PowerShell(管理员)(A)打开:

1、输入cmd 回车;

2、输入 你的解压包所在的盘符(如:D:)回车;

3、输入 cd   你的解压包的bin文件夹的地址 回车(如:cd E:\mysql-8.0.26-winx64\bin );

提示:下列指令可以直接复制到cmd里 执行,一定要按顺序执行

4、初始化, 输入 :

mysqld –initialize-insecure –user=mysql

你的解压包的下将生成一个data的文件夹。

如果你要重置数据库建议直接删除mysql解压包,重新复制一个,二次初始化会报错。

 5、安装服务,输入:

mysqld install

提示:删除服务:mysqld remove。

6、启动服务,输入:

net start mysql

7登录数据库,输入:

mysql -u root -p

因为初始化的原因,第一次是不需要密码的 直接回车;

8、修改登录密码 输入:

SET PASSWORD = ‘你的密码’ ; 

9、刷新权限 输入:

flush privileges ;

10、退出 输入:

qiut

或者

exit

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/128371.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!