first, find slow query
We prepared the data for the occurrence of the slow query, which allows us to find the slow query and log it to the file.
3. Record Slow queries
At this point we already have the cost of making the slow query happen. Execute the following statement and you will know what is slow! Check! Polling
[Plain]View Plaincopy
- Select Empno from emp where ename= ';
A query statement that obviously couldn't find the result was executed for almost 3 seconds.
At this point, the SQL statement should be recorded as a DBA, written in Notepad or in a notebook? Do not think too much, do not have to remember, MySQL provides a slow query log function, automatically help you record slow query statements.
1) Log The SQL of the slow query to the logs
First you want to open the slow query log file logger
Use
[Plain]View Plaincopy
- Show variables like ' slow% ';
You will find that by default the slow query logger shuts down
Use
[Plain]View Plaincopy
- Set global slow_query_log=on;
Open the
At this point you will find a log file named after your native name in the Data folder in the MySQL installation directory
The slow query operation is performed again at this time
Open log file discovery occurrence record
Later, you can only check the log file periodically to find the slow query statement.
Attention:
After finding the slow query statement, to confirm the slow query by repeatedly using the SELECT statement, note that only SELECT statements can be used, even if the original statement is delete or update, etc., also use Select Instead, because only select does not dirty the database
2) Another way to find slow query statements
If you use hibernate for the development of the Java EE, you can use the method.
In the page, when the response to an action is found to be slow, look at the Hibernate output SQL statement from the Eclipse console, which is a slow query statement.
Database Tuning Tutorial (iii) record slow query