Explain how to open slow query log in mysql database in detail

  • 2021-07-22 11:42:27
  • OfStack

Database Open Slow Query Log

Modify the configuration file

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


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

The first sentence is used to define the path of the slow query log (if it is an linux system, it will involve permission issues)

The second sentence is used to define that a query that takes more than how many seconds is a slow query in seconds.

Check whether configuration verification was successfully configured:


// View slow query time, unit: s
show variables like "long_query_time";

// View Slow Query Configuration 
show status like "%slow_queries%";

// View slow query log path 
 show variables like "%slow%";
 

Perform a slow query operation to verify that logging is recorded:

The amount of data in the environment built by ourselves is small, so it is difficult to simulate and execute slow queries, which can be replaced by the following statement simulation:


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

 

View the number of slow queries:


show global status like '%slow%';

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: