MySQL Variables long_query_time 数据库 参数变量解释及正确配置使用

本站中文解释

**MySQL参数变量long_query_time及用途:**

long_query_time 参数用来定义慢查询等待时间,即 MySQL服务器要求客户端等待查询结果返回时间。可以通过该参数来监视服务器上各脚本执行的时间,结合 slow query log ,可以找到让系统性能较慢的SQL语句。

**如何设置:**

可以以下面的任一方式来设置 MySQL 参数 long_query_time:

1. 使用命令行编辑器编辑 MySQL 的 my.cnf 文件,在 [mysqld] 节中添加:

long_query_time=10

2. 使用 MySQL 提供的命令行客户端工具来设置:

SET GLOBAL long_query_time = 10;

3. 使用 MySQl Workbench 配置,例如在 connection 选项中配置:

Long Query Time = 10

官方英文解释

long_query_time

Command-Line Format --long-query-time=#
System Variable long_query_time
Scope Global, Session
Dynamic Yes
Type Numeric
Default Value 10
Minimum Value 0
Maximum Value 31536000
Unit seconds

If a query takes longer than this many seconds, the server
increments the Slow_queries
status variable. If the slow query log is enabled, the query
is logged to the slow query log file. This value is measured
in real time, not CPU time, so a query that is under the
threshold on a lightly loaded system might be above the
threshold on a heavily loaded one. The minimum and default
values of
long_query_time
are 0 and 10, respectively. The maximum is 31536000, which is
365 days in seconds. The value can be specified to a
resolution of microseconds. See
Section 5.4.5, “The Slow Query Log”.

Smaller values of this variable result in more statements
being considered long-running, with the result that more space
is required for the slow query log. For very small values
(less than one second), the log may grow quite large in a
small time. Increasing the number of statements considered
long-running may also result in false positives for the
excessive Number of Long Running Processes
alert in MySQL Enterprise Monitor, especially if Group Replication is enabled.
For these reasons, very small values should be used in test
environments only, or, in production environments, only for a
short period.


数据运维技术 » MySQL Variables long_query_time 数据库 参数变量解释及正确配置使用