Mysql slow query Analysis Method

Source: Internet
Author: User

This article mainly introduces the MySQL slow query analysis method. Some days ago, I set a record to query SQL statements that are slower than 1 second in the MySQL database. There are several very well-configured methods, and the names of several parameters cannot be remembered, so I made a note again.

For troubleshooting and identifying performance bottlenecks, the most common problems are slow MySQL queries and queries without indexes.

OK. Start to find the SQL statement that is not "refreshing" in MySQL.

 MySQL slow query Analysis Method 1:

I am using this method.

MySQL and later versions Support recording slow SQL statements.

MySQL> show variables like long %;

Note: This long_query_time is used to define how many seconds are slower to calculate as "Slow query"

+ ----------------- + ----------- +
| Variable_name | Value |
+ ----------------- + ----------- +
| Long_query_time | 10.000000 |
+ ----------------- + ----------- +
1 row in set (0.00 sec)
MySQL> set long_query_time = 1;

Note: I set 1, that is, if the execution time exceeds 1 second, the query is slow.

Query OK, 0 rows affected (0.00 sec)
MySQL> show variables like slow %;
+ --------------------- + --------------- +
| Variable_name | Value |
+ --------------------- + --------------- +
| Slow_launch_time | 2 |
| Slow_query_log | ON |

Note: whether to Enable Logging

| Slow_query_log_file |/tmp/slow. log |

NOTE: Where to set

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.