MySQL Optimization-enable MySQL slow query log and analysis tool mysqldumpslow

Source: Internet
Author: User
Tags mysql slow query log

MySQL Optimization-enable MySQL slow query log and analysis tool mysqldumpslow

1. It is very easy to enable MySQL slow query logs. You only need to add the following in the MySQL configuration file my. cnf:
[Mysqld]
Slow_query_log = 1-enable slow query log
Slow_query_log_file =/data01/mysqldata/3306/slow_query.log -- slow query log storage location, which can be written as needed. Generally, it is the data storage directory.
Long_query_time = 10 seconds. The default value is 10, indicating that records exceed 10 seconds.

Slow_launch_time = 2-indicates that if the thread creation takes longer than this value, the slow_launch_threads counter will increase
Log_queries_not_using_indexes = OFF -- if it is set to ON, the query records do not use the index. It is disabled by default.

Note: run show global status like '% slow %'; to view the slow_launch_threads counter.

2. Set the time:
Mysql> set long_query_time = 5;
Mysql> show variables like 'long % ';

3. Slow query log analysis tool mysqldumpslow.
If the slow query log contains many records, you can use the mysqldumpslow tool (which is included in the MySQL client installation) to classify and summarize the slow query logs. Mysqldumpslow classifies and summarizes log files and Displays summary results.

$ Mysqldumpslow-s t-t 10-g "left join"/data01/mysqldata/3306/slow_query.log
Obtain the query statements containing the left join in the first 10 results sorted by time.

The mysqldumpslow command can be used to obtain various query statements that we need very clearly. Monitoring, analyzing, and optimizing MySQL query statements is an important step for MySQL optimization. After the slow query log is enabled, the log record operation may occupy CPU resources to some extent, affecting mysql performance. However, you can enable it to locate the performance bottleneck in stages.

This article permanently updates the link address:

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.