MySQL slow query is to record SQL statements that run slowly in the log. This function needs to be turned on to 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 SQL will be logged after execution. Here 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 video tutorial
The above is the detailed content of What is mysql slow query. For more information, please follow other related articles on the PHP Chinese website!