Home > Database > Mysql Tutorial > How to enable mysql slow query log

How to enable mysql slow query log

王林
Release: 2020-01-26 20:52:45
forward
2078 people have browsed it

How to enable mysql slow query log

First we need to understand the four parameters:

slow_query_log # 是否开启慢查询日志,默认OFF,开启则设置为 ON。
slow_query_log_file # 慢查询日志文件存储位置。
log_queries_not_using_indexes # 是否把没有使用到索引的SQL记录到日志中,默认OFF,开启则设置为 ON。
long_query_time # 超过多少秒的查询才会记录到日志中,注意单位是秒。
Copy after login

Then execute the statement settings (this method will become invalid after restarting MySQL)

(Related video tutorial Recommended: mysql video tutorial)

After knowing the meaning of the parameters, we can directly set the parameters we need. I am using global settings here.

SET GLOBAL slow_query_log = 'ON';
SET GLOBAL slow_query_log_file = '文件路径(绝对路径)';
SET GLOBAL log_queries_not_using_indexes = 'ON';
SET GLOBAL long_query_time = 1;  # 这里需要注意下,long_query_time参数设置后需要下次会话后才生效,当前会话查询还是原来的数值
Copy after login

Last modification of the configuration file (permanent settings)

If you want it to not be invalid after restarting MySQL, you can modify the MySQL configuration file. Add the following statement in the configuration file:

slow_query_log="ON"
slow_query_log_file="文件路径(绝对路径)"
log_queries_not_using_indexes="ON"
long_query_time=1
Copy after login

It will take effect after restarting.

Recommended related articles and tutorials: mysql tutorial

The above is the detailed content of How to enable mysql slow query log. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template