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:
- mysql> show variables like '%slow%';
- +------------------+-------+
- | Variable_name | Value |
- +------------------+-------+
- | log_slow_queries | ON |
- | slow_launch_time | 2 |
- +------------------+-------+
- mysql> show global status like '%slow%';
- +---------------------+-------+
- | Variable_name | Value |
- +---------------------+-------+
- | Slow_launch_threads | 0 |
- | Slow_queries | 4148 |
- +---------------------+-------+
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
- log-slow-queries=/data/mysqldata/slowquery.log
- 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