gpt4 book ai didi

Mysql 慢查询日志不遵守 long_query_time 变量,记录真正快速的查询

转载 作者:行者123 更新时间:2023-11-29 04:34:44 24 4
gpt4 key购买 nike

我正在运行 mysql 5.5 并且正在调试性能问题。我启用了 mysql 慢速日志记录。这些是我在 my.cnf 中的相关设置:

log_slow_queries    = /var/log/mysql/mysql-slow.log
long_query_time = 10
log-queries-not-using-indexes

Mysql 确实在创建和写入慢速查询日志。但是,它会记录大量运行速度比 long_query_time 参数指定的查询快得多的查询。

举几个例子:

# Query_time: 0.000142  Lock_time: 0.000039 Rows_sent: 1  Rows_examined: 1 
# Query_time: 0.000081 Lock_time: 0.000024 Rows_sent: 1 Rows_examined: 1
# Query_time: 0.000116 Lock_time: 0.000034 Rows_sent: 1 Rows_examined: 1

实际上没有任何查询实例的查询或锁定时间加在一起大于 0.1。根据我对 long_query_time 参数应该做什么的阅读,我不希望在慢速查询日志中找到这些查询。

最佳答案

编辑 my.cnf 不会将更改应用到正在运行的实例。 my.cnf必须重启MySQL服务才能生效。

或者,您可以使用 SET GLOBAL long_query_time = 10 在当前运行的实例中应用等效更改。

我的习惯是两者:编辑my.cnf,让下次重启MySQL服务时生效,然后我也用SET GLOBAL来对正在运行的实例应用相同的更改。了解并非每个 MySQL 服务器变量都可以像那样动态更改。

另请注意,只有 客户端连接才能获得该全局值。现有客户端连接将继续使用其连接开始时有效的先前全局值。


回复你的评论:

请注意,您设置了 log-queries-not-using-indexes。这意味着记录所有不使用索引的查询,即使查询比 long_query_time 更快。

https://dev.mysql.com/doc/refman/5.5/en/slow-query-log.html说:

The server uses the controlling parameters in the following order to determine whether to write a query to the slow query log:

  • The query must either not be an administrative statement, or --log-slow-admin-statements must have been specified.

  • The query must have taken at least long_query_time seconds, or log_queries_not_using_indexes must be enabled and the query used no indexes for row lookups.

  • The query must have examined at least min_examined_row_limit rows.

请注意,“不使用索引”有点违反直觉。 https://dev.mysql.com/doc/refman/5.5/en/server-options.html#option_mysqld_log-queries-not-using-indexes说:

[The log-queries-not-using-indexes] option does not necessarily mean that no index is used. For example, a query that uses a full index scan uses an index but would be logged because the index would not limit the number of rows.

关于Mysql 慢查询日志不遵守 long_query_time 变量,记录真正快速的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46474299/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com