How has slow query log changed in recent MySQL versions?

The slow query log feature in MySQL has seen several enhancements and changes over the recent versions, particularly aimed at providing better performance troubleshooting and query optimization tools. Here’s an overview of some notable changes:

  • Dynamic Configuration: Starting from MySQL 5.7, the slow_query_log variable can be set dynamically without requiring a server restart. This makes it easier for administrators to enable or disable slow query logging on the fly.
  • Log Output Options: MySQL 5.7 introduced the ability to log slow queries in various formats such as tables in the Performance Schema, which allows for more flexible querying and reporting on logged queries.
  • Improved Performance Tracking: The 'long_query_time' setting now allows floating-point values, enabling more precise control over what constitutes a slow query.
  • Query Examples: The slow query log can now include query examples to make it easier to identify problematic queries directly from the logs.
  • Partial Logging: With recent versions, users can specify conditions under which queries are logged, reducing unnecessary logging and focusing on specific issues.

Here is a simple example of how to enable slow query logging in your MySQL configuration:

-- Enable the slow query log SET GLOBAL slow_query_log = 'ON'; -- Set the long query time to 1 second SET GLOBAL long_query_time = 1; -- Optionally log output to a specific file SET GLOBAL slow_query_log_file = '/var/log/mysql/mysql-slow.log';

MySQL slow query log MySQL 5.7 performance tuning database optimization