版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/stupid56862/article/details/86489439
环境
本文 mysql 版本为 5.6.41
配置文件
之前没怎么接触过 mysql 的配置文件 , 安装完成 mysql 后 , 没有发现配置文件。
习惯性的 Google , 找了篇博客, copy 了一下配置文件,结果死活不生效 。 我 copy 来的配置文件名称叫 my-default.ini
接下来分析下为什么不生效 ,命令行执行 :
mysql --help
往上拉,你会看到这么两行文字 ,表示以给定顺序从以下文件中读取默认选项:
Default options are read from the following files in the given order:
C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf D:\mysql\mysql-5.6.41-winx64\my.ini D:\mysql\mysql-5.6.41-winx64\my.cnf
这就明白了为什么我的配置文件没有生效 ! 原来名字不对 , mysql 没有识别 !
同时也告诉我们 , mysql 读取配置文件是有优先级的 ! 如果你的配置文件名称正确,配置文件却没有生效,你需要看看其他路径下是否有相应的配置文件。
下面是我修改后的配置文件 my.ini , 大家不要 copy , 请按需修改自己的 mysql 配置
[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.
basedir = D:\mysql\mysql-5.6.41-winx64\
datadir = D:\mysql\mysql-5.6.41-winx64\data
port = 3306
# Set Slow Query Log
long_query_time = 1
slow_query_log = 1
slow_query_log_file =D:\mysql\mysql-5.6.41-winx64\log\\slowquery.log
log_queries_not_using_indexes = 1
#Set General Log
general_log = 1
general_log_file=D:\mysql\mysql-5.6.41-winx64\log\general.log
#skip-grant-tables
#server_id = .....
# 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
修改配置文件后,想要使配置文件生效,需要重启 mysql 服务 。
1. 快捷键 windows + r , 然后输入 services.msc
2. 找到 mysql 服务,重启该服务即可。
如何知道配置文件有没有生效呢 ? 例如 , 我这里新配置了慢查询日志的路径 slow_query_log_file
有两种方法 :
1.重启服务后,查看你配置的 log 目录下是否生成对应的 log 文件
2.mysql 中执行 show variables like “%log%” 找到对应的配置,看配置路径是否修改。如 :
show variables like "%log%"
显示结果中包含 :
| slow_query_log | ON |
| slow_query_log_file | D:\mysql\mysql-5.6.41-winx64\log\slowquery.log |