Use the MySQL slow query log to monitor efficiency issues with SQL

Source: Internet
Author: User
Tags mysql slow query log

Input command:show variables like ' slow% '

You can find that Slow_query_log is OFF (default), indicating that the slow query log is not turned on

Slow_query_log_file for slow query log file

There are two ways to turn on the slow query log

Method One: Temporarily open

Set Global slow_query_log = on;

#没有使用索引的sql将会被记录入慢查询日志

Set Global log_queries_not_using_indexes = on;

SQL #查询时间大于等于long_query_time (in seconds) will be logged into the slow query log

Set Global long_query_time = 1; # 1 means that SQL records greater than or equal to 1s are in the slow query log and can be changed to milliseconds or less

Method Two: Permanent Open

After you change the MySQL profile my.ini (Windows),[mysqld] , append the parameters in the red box:

Here Long_query_time = 0 means that all queries are logged to the slow query log, but the actual application should give a reasonable value in order to detect whether the configuration is in effect.

Save the configuration file and remember to restart Apache

When the slow query log is turned on, the SQL that is monitored is written to Slow_query_log_file , in the following format:

Since the slow query log is generated, of course, there are slow query log analysis tools , such as: MySQL comes with the Mysqldumpslow, there is not much to say.

Use the MySQL slow query log to monitor efficiency issues with SQL

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.