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".
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
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!