How to enable slow query logs for mysql Databases
Enable slow query log for the database
Modify configuration file
Add the following two sentences to the configuration file my. ini:
Log-slow-queries = C: \ xampp \ mysql_slow_query.loglong_query_time = 3
The first statement is used to define the path for slow query logs (for linux systems, permission issues are involved)
The second clause is used to define the number of seconds that have elapsed since the query time is slow. Unit: seconds.
Check whether configuration verification is successful:
// View the slow query time. Unit: sshow variables like "long_query_time ";
// View the slow query configuration. show status like "% slow_queries % ";
// View the slow query Log Path show variables like "% slow % ";
Perform the slow query operation to verify whether logs are recorded:
The self-built environment has a small amount of data and it is difficult to simulate slow queries. You can simulate the following statement instead:
Select sleep (10), name from user where userid = 1;
View the number of slow queries:
Show global status like '% slow % ';
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!