SQL for MySQL logging slow query

Source: Internet
Author: User

In the daily development, often encounter the page open very slow situation, by excluding, determined, is the impact of the database, in order to quickly find the specific SQL, can be logged through the MySQL method.

--Open the SQL execution logging function

Set global log_output= ' TABLE '; --Output to table

Set global log=on; --Open all commands to perform the logging function General_log, all statements: successful and unsuccessful.

Set global log_slow_queries=on; --Open slow query SQL record Slow_log, execute successfully: Slow query statement and statement with unused index

Set global long_query_time=0.1; --Slow query time limit (seconds)

Set global log_queries_not_using_indexes=on; --Record SQL statements that do not use indexes

--Querying SQL execution records

SELECT * from Mysql.slow_log order by 1; --Successful execution: Slow query statements, and statements that do not use indexes

SELECT * from Mysql.general_log order by 1; --All statements: successful and unsuccessful.

--Close SQL execution record

Set global Log=off;

Set global Log_slow_queries=off;

--Long_query_time parameter description

--v4.0, 4.1, 5.0, v5.1 to 5.1.20 (included): Slow query parsing at millisecond level is not supported (1-10 seconds of support accuracy);

--5.1.21 and later versions: supports slow query analysis at millisecond level, such as 0.1;

--6.0 to 6.0.3: Slow query parsing at millisecond level is not supported (1-10 seconds for precision);

--6.0.4 and later: support for millisecond-level slow query analysis;

With the SQL recorded in the log, quickly locate the specific file, optimize SQL to see if the speed is improved?

RELATED LINKS

Related Article

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.