Database Tuning Tutorial (iii) record slow query

Source: Internet
Author: User

first, find slow query
The last thing we do is to prepare for the occurrence of slow queries, which allows us to find slow queries and record them in a 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

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

Show variables like ' slow% ';

You will find that by default the slow query logger shuts down

Use

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.

at the end of this chapter, we will explain how to use MySQL's performance Analysis command explain in the next chapter.

Database Tuning Tutorial (iii) record slow query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.