MySQL Slow Query configuration

Source: Internet
Author: User
Tags mysql command line mysql slow query log

MySQL Slow query1. 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:Method One: Locate the MySQL configuration file my.cnf (/ETC/MY.CNF) and add the configuration statement for the slow query below mysqld (Note: Be sure to join below [mysqld], if it is in [Mysqld_safe] The following configuration statements are not valid. I have made this mistake during the configuration process and experienced the pain!)
 
 Log-slow-queries: On behalf of the MySQL slow query log storage directory, this directory file must have write permissions.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 it to restart a mysql later:Service mysqld Restartmethod Two: Perform the following operations on the MySQL command line: (Solve ing)
 
 set the state of the MySQL variable by using the SET command. But my test never passed, and I suspect it could be a MySQL version of the problem.www.2cto.com
 
 Online to find a lot of information, but have not been resolved, I hope the master can help me answer.after the configuration is complete, let's look at the current status again, and you'll find the following:
 
 indicates that the slow query service has been turned on and the time limit is 2 seconds.Let's take a look at whether the Mysql-slow.log file is automatically created under the/var/lib/mysql/directory.
 
 the cat mysql-slow.log discovery file already exists. Only the file does not have a task SQL record. So now let's test the execution of an SQL statement that is more than Long_query_time .
 
 after executing a 3-second SQL statement, the SQL statement should be logged in the Mysql-slow.log file without exception. Ok! We cat mysql-slow.log a bit.
 
 sure enough. The entire configuration process for slow queries is complete. reprinted from Http://www.2cto.com/database/201207/143358.html

MySQL Slow Query configuration

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.