mysql5.7慢查询开启配置

1、问题

    当然又被度娘(我冤枉)坑了噻,网友说配置文件写下面三行:

log-slow-queries=D:Program Filesmysql-5.7.11-winx64datalow.log
long_query_time=2 (记录超过的时间,默认为10s) log-queries-not-using-indexes (log下来没有使用索引的query,可以根据情况决定是否开启)

    俺信了噻,就去my.ini中加入了这三行配置,net start mysql,启动不了了,查看错误日志:

[ERROR] unknown variable 'log-slow-queries=D:Program Filesmysql-5.7.11-winx64datalow.log'

2、解决方法

    无奈之下,只好去mysql官方网站去查去了,头疼,不喜欢看英文啊,没中文好看,中文多漂亮啊,要姿势有姿势,要内涵有内涵。

    http://www.mysql.com,进入documentation tab页,点那个叫[Reference Manual]的大按钮,还算漂亮;

   懵逼了吧,这怎么找啊?

    当然最快的是搜索slow query,mysql官网有这功能,一定比度娘准确,然后会出一堆slow query的连接,选一个对应的版本就可以;

    不过,俺比较懒,俺喜欢猜过去,第一猜,如果咱是手册编写人员,会把这个慢查询放哪啊?肯定有个配置管理的章节吧

    很凑巧,右侧树列表有个MySQL server Administration,点开它

    一眼就发现了MySQL server logs,继续点开,一定会有一个叫做slow query log的链接,点开它。扫了扫,找到这两段话

    If you specify no name for the slow query log file, the default name is host_name-slow.log. The server creates the file in the data directory unless an absolute path name is given to specify a different directory.

    如果你设置慢查询日志文件名,默认会在data目录下创建一个host_name-slow.log的文件;

    To disable or enable the slow query log or change the log file name at runtime, use the global slow_query_log and slow_query_log_file system variables. Set slow_query_log to 0 (or OFF) to disable the log or to 1 (or ON) to enable it. Set slow_query_log_file to specify the name of the log file. If a log file already is open, it is closed and the new file is opened.

 

    为了使慢查询生效,需要设置slow_query_log=1或者on,否则设置为0或off。设置slow_query_log_file指定日志文件名

 看清楚了,不是log-slow-queries,看来这个是老版本的mysql配置写法,5.7是用slow_query_log_file,如果是我,我也改成这个变量名,什么叫
 log-slow-queries,完全没有slow_query_log_file语义明确。
原文地址:https://www.cnblogs.com/sdnu/p/5375434.html