How to enable MySQL slow Query

Source: Internet
Author: User

If we need to implement MySQL slow query at the microsecond level, how should we implement it? The following describes how to enable MySQL slow query.

MySQL slow query:

 
 
  1. mysql> show variables like '%slow%';  
  2. +------------------+-------+  
  3. | Variable_name | Value |  
  4. +------------------+-------+  
  5. | log_slow_queries | ON |  
  6. | slow_launch_time | 2 |  
  7. +------------------+-------+  
  8. mysql> show global status like '%slow%';  
  9. +---------------------+-------+  
  10. | Variable_name | Value |  
  11. +---------------------+-------+  
  12. | Slow_launch_threads | 0 |  
  13. | Slow_queries | 4148 |  
  14. +---------------------+-------+ 

Slow query is enabled in the configuration. If the execution time exceeds 2 seconds, the query is slow. The system displays 4148 slow queries. You can analyze the slow query logs, find out the problematic SQL statement. The slow query time should not be too long. Otherwise, it is of little significance. It is best to set it to within 5 seconds. If you need a slow query in microseconds, you can patch MySQL, remember to find the corresponding version.

Opening the slow query log may have a slight impact on the system. If your MySQL is a master-slave structure, you can consider opening the slow query log of one of the slave servers, in this way, you can monitor slow queries with little impact on system performance.

Enable MySQL slow query in Linux
The configuration file of MySQL in Windows is usually my. cnf. Find [mysqld] and add

 
 
  1. log-slow-queries=/data/mysqldata/slowquery.log  
  2. long_query_time=2 

Note:
Log-slow-queries = F: \ MySQL \ log \ mysqlslowquery. log is the location where MySQL slow query logs are stored. Generally, this directory requires the write permission of the MySQL running account. Generally, this directory is set to the MySQL data storage directory;
2 In long_query_time = 2 indicates that the query takes more than two seconds to record.

Introduction to MySQL CONVERT Functions

How to modify MySQL character set in Liunx

Take you to understand mysql Variables

Provides you with an in-depth understanding of MySQL user permissions.

MySQL user permission setting method

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.