How to open Mysql slow query log
This article focuses on "how to open the Mysql slow query log", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to open the Mysql slow query log.
Check whether slow query is enabled on the current server:
1. Quick way to run the sql statement show VARIABLES like "% slow%"
2. Go directly to my.conf to check.
Configuration in my.conf (add under [mysqld])
[mysqld]
Log-slow-queries = / data/mysql/10-9-138-42-slow.log
Long_query_time = 1 # unit is second
Log-queries-not-using-indexes
Use the SQL statement to modify: cannot be modified according to the items in my.conf. Modified through "show VARIABLES like" slow% ""
Statement, run the following sql:
Set global log_slow_queries = ON
Set global slow_query_log = ON
Set global long_query_time=0.1; # set sql statements greater than 0.1s to record
After that, restart the database of Mysql: start it with service: service mysqld start
Information format of slow query log files:
Select sleep (3); this is the key message, indicating that the statement was executed at that time
Set the relationship between millisecond level and mysql version
Many online materials show that in versions prior to 5.21, the long_query_time in my.conf can only be set to a minimum of 1 (that is, at least 1 second). I bumped into myself and found that I could achieve it in other ways.
I didn't try "long_query_time = 0.1" because the database server was running. A reboot is required. So I didn't try. I implement the slow log query record through the global variable setting.
Millisecond level recording can be achieved by setting global variables:
Set global long_query_time = 0.01,
The mysql version on my server is 5.5.53
I've tried to work this way.
How to test whether your query
Will be recorded?
Run statement
Select sleep (3)
I deliberately set a 3-second delay, and then this statement is recorded in the log file as expected (because the previous setting was more than 0.1 seconds).
At this point, I believe you have a deeper understanding of "how to open the Mysql slow query log". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!