Example of enabling slow query log in mysql

Source: Internet
Author: User
Tags mysql command line

When the project is large, mysql processes a large amount of data every day, and some slow queries are inevitable. At this time, we need to enable the slow query log to see which SQL statements need to be optimized. The following describes how to enable mysql slow log query:

 

1. In mysql command mode, run "set global slow_query_log = on;" to enable slow query logs.

2. Take window as an example. Open the mysql configuration file "my. ini" and add the following configuration later:

Log-slow-queries = E: \ mysql_log \ slow_query.loglong_query_time = 0.8


"Log-slow-queries" indicates the location where the log is saved. Note that "\" should be used for the path in the window, and escape it here, so use "\", make sure that the directory has been created in advance, or no logs will be logged;


"Long_query_time = 0.8" indicates that the query (select) takes more than 0.8 seconds and logs are recorded.

 

3. After saving the configuration, restart the mysql service. Run "show variables like '% slow %';" in the mysql command line to check whether the result is as follows:

 

 

4. Then I tried to check several SQL statements (records without indexes) and found that slow queries have been successfully recorded in the log file, as shown in the following figure:

 

 

So far, the configuration of slow query is complete.

 

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.