Home  >  Article  >  Database  >  Mysql database enables slow query log

Mysql database enables slow query log

迷茫
迷茫Original
2017-03-26 11:34:181090browse

Modify the configuration file

Add the following two sentences to the configuration file my.ini

 log-slow-queries = C:\xampp\mysql_slow_query.log2 long_query_time=3

The first sentence is used to define the path of the slow query log ( If it is a Linux system, permission issues will be involved)
The second sentence is used to define a query that takes more than how many seconds to be a slow query, unit: seconds.

Check the configuration and verify whether the configuration is successful:

//查看慢查询时间,单位:s
show variables like "long_query_time";
//查看慢查询配置情况
show status like "%slow_queries%";
//查看慢查询日志路径
 show variables like "%slow%";

Perform the slow query operation and verify whether the log is recorded:

Build it yourself The amount of data in the environment is small, and it is difficult to simulate the execution of slow queries. You can simulate it with the following statement:

SELECT SLEEP(10),name from user where userid=1;

Check the number of slow queries:

show global status like '%slow%';

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

Statement:
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