mysql slow log
时间: 2023-10-14 12:21:10 浏览: 45
MySQL slow log is a feature that allows you to track slow-running queries in your MySQL database. It records any query that takes longer than a configurable amount of time to execute and writes it to a log file.
To enable the slow query log, you need to add the following lines to your MySQL configuration file:
```
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 2
```
The `slow_query_log` variable turns on the slow query log, while `slow_query_log_file` specifies the location of the log file. The `long_query_time` variable sets the threshold for the query execution time, in seconds. In this example, any query that takes longer than 2 seconds to execute will be logged.
Once you have enabled the slow query log, you can use various tools to analyze the log file and identify slow-running queries. For example, you can use the `mysqldumpslow` tool to summarize the log file and sort the queries by execution time or number of occurrences.
Analyzing the slow query log can help you identify performance bottlenecks in your MySQL database and optimize your queries for better performance.