MySQL Slow query

Source: Internet
Author: User
Tags mysql slow query log

Transferred from: http://www.cnblogs.com/gzgccsu/archive/2013/01/23/2873598.html

1. What is the use of slow queries?

It records all SQL statements that execute more than long_query_time time, helping you to find SQL that executes slowly, so we can optimize these SQL.

2. How do I turn on slow queries?

First we check if the MySQL server's slow query status is turned on. Execute the following command:

We can see that the current log_slow_queries status is off, indicating that no slow query is currently turned on.

It is very simple to turn on slow queries, as follows:

Find MySQL configuration file under Linux My.ini, add the configuration statement of slow query under MYSQLD (Note: Be sure to add below [mysqld]) "Mysqld server-side Configuration"

Log-slow-queries: On behalf of the MySQL slow query log storage directory, this directory file must have write permission;

You need to write an absolute path under Windows, such as: log-slow-queries= "C:/Program files/mysql/mysql Server 5.5/log/mysql-slow.log"

Long_query_time: Maximum execution time. (, MSYQL will record all the execution time more than 2 SQL statements, here is the test time, the time should not be too small preferably within 5-10 seconds, of course, according to their own standards);

Configure to restart a MySQL service later

Note: Turning on slow queries will have a performance impact and can be turned on for tuning. Logging slow SQL can also be implemented in the program. Use the time difference before and after SQL to log the SQL that is running slowly.

  

MySQL Slow query

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.