Mysql slow query Configuration

Source: Internet
Author: User


Mysql slow query configuration MYSQL slow query 1. What is the use of slow query? It records all SQL statements that have been executed longer than long_query_time, and helps you find slow SQL statements to optimize these SQL statements. 2. How to enable slow query? First, check whether the slow query status of the MYSQL server is enabled. Execute the following command:

We can see that the current log_slow_queries status is OFF, indicating that the slow query is not enabled currently. it is very easy to enable slow query. The operation is as follows: Method 1: Find the mysql configuration file my. cnf (/etc/my. cnf), add the slow query configuration statement below mysqld (Note: Be sure to add it below [mysqld, adding a configuration statement under [mysqld_safe] does not take effect. I made this mistake during the configuration process, and I personally experienced the pain !)

Log-slow-queries: indicates the log storage directory of MYSQL slow query. This directory must have write permission ,. long_query_time: Maximum execution time. (MSYQL records all SQL statements that have been executed for more than two times. The test time is used here. The time should not be too small. It is best to set the time to within 5-10 seconds, depending on your own standards ); after the configuration is complete, restart MYSQL: service mysqld restart Method 2: execute the following operations under the mysql command line: (solving ing)

Use the set command to set the MYSQL variable status. However, I have never passed the test. I suspect it may be a problem with the MYSQL version. www.2cto.com

I have found a lot of information online, but it has not been solved. I hope the experts will help me solve the problem by passing by. After the configuration is complete, let's check the current status. You will find the following:

It indicates that the slow query service has been enabled and the time limit is 2 seconds. Let's check whether the mysql-slow.log file is automatically created under the/var/lib/mysql/directory.

Cat mysql-slow.log found that the file already exists. But there is no job SQL record in the file. Now let's test the execution of an SQL statement that exceeds long_query_time.

After a 3 second SQL statement is executed, this SQL statement should be recorded in the mysql-slow.log file without accident. OK! Let's get a cat mysql-slow.log.

Sure enough. The whole configuration process of slow query is completed.

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.