【问题标题】:mysql 5.7 log-slow-queries errormysql 5.7 日志慢查询错误
【发布时间】:2016-08-21 23:39:43
【问题描述】:

我正在尝试在 mysql 5.7 上启用慢速查询日志记录并收到此错误:

2016-04-27T14:55:51.934612Z 0 [错误] 未知变量 'log-slow-queries=/var/log/mysql-query.log'

2016-04-27T14:55:51.934639Z 0 [错误] 中止

在我的 /etc/my.cnf 文件中,我定义了“log-slow-queries=/var/log/mysql-query.log”,但我假设在 5.7 中这是无效的。启用查询日志记录的正确 my.cnf 设置是什么? 谢谢,

【问题讨论】:

  • 5.1.29 版弃用了该语法(以及其他一些日志语法); 5.6.1 删除它。是什么产生的?

标签: mysql my.cnf mysql-slow-query-log


【解决方案1】:

MySQL 系统变量的名称是 slow_query_log_file

要启用它,您需要将 slow_query_log 设置为 ON 或 1

MySQL Reference Manual: sysvar_slow_query_log_file

MySQL Reference Manual: sysvar_slow_query_log

【讨论】:

  • 慢查询是否也意味着“所有查询”?我的总体目标是启用所有查询的日志记录,但我看到的只是关于慢查询的 cmets。没有启用所有查询的其他标志,是吗?
  • general_log 可以记录所有内容。它可以增长得非常快。我们只是暂时启用它以进行调试。参考:http://dev.mysql.com/doc/refman/5.7/en/query-log.html
  • 在 Stackoverflow 中有许多 awnsers 使用 log-slow-queries 设置路径...谢谢您的 anwser。
【解决方案2】:

log-slow-queries 已弃用

http://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html

# Here you can see queries with especially long duration
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-queries.log
long_query_time = 1

【讨论】:

  • 截至此评论的 5.7.20 中的默认值不正确。您必须如上所述手动更新它。
  • 同样在mysqld 命令上,现在是--slow-query-log,而不是--log-slow-time
猜你喜欢
  • 1970-01-01
  • 2012-06-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-24
  • 1970-01-01
  • 2015-10-31
  • 2011-01-01
  • 2010-10-09
相关资源
最近更新 更多