Home > Database > SQL > body text

What is slow query

hzc
Release: 2020-06-29 16:22:37
Original
5472 people have browsed it

In addition to using EXPLAIN to output the execution plan, the method of analyzing MySQL statement query performance can also allow MySQL to record statements that query more than the specified time. We call SQL statement queries that exceed the specified time "slow queries".

What is slow query

MySQL slow query records SQL statements that run slowly in the log. This function needs to be turned on before it can be used.

Write in the MySQL configuration file my.cnf:

long_query_time = 10
log-slow-queries = /var/lib/mysql/mysql-slow.log
Copy after login

long_query_time refers to how long the execution of SQL will be recorded in the log, here it is 10 seconds.
log-slow-queries is set to write the log there (in the example, the slow query log will be written to the file /var/lib/mysql/mysql-slow.log). When it is empty, the system will write the slow query log. Give the hostname and add slow.log. If the parameter log-long-format is set, all queries that do not use indexes will also be logged.

This is a very useful log. It has a small impact on performance (assuming all queries are fast) and emphasizes those queries that require the most attention (indexes are missing or not being used optimally).

Recommended tutorial: "mysql tutorial"

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

Related labels:
source:php.cn
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