Slow queries can affect database and server performance.
The slow query log consists of SQL statements that took more than long_query_time seconds to execute.
This greatly simplifies the task of finding inefficient or time-consuming queries.
By default, the slow query log is disabled
🔥 How to enable?
Login to MySQL, database abc_prod
shell> mysql -u root -p abc_prod
Enable slow query log
mysql> SET GLOBAL slow_query_log = 'ON';
Check path to log file
mysql> SHOW VARIABLES LIKE 'slow_query_log_file';
+---------------------+-----------------------------+
| Variable_name | Value |
+---------------------+-----------------------------+
| slow_query_log_file | /var/lib/mysql/db3-slow.log |
+---------------------+-----------------------------+
1 row in set (0.00 sec)
Change long query time to 5 seconds - default is 10 seconds
mysql> SET GLOBAL long_query_time = 5;
Logout MySQL session then login again
Take a small test to ensure slow query log is enable
❓ What is slow query log?
🔥 How to enable?
Login to MySQL, database
abc_prod
Enable slow query log
Check path to log file
Change long query time to 5 seconds - default is 10 seconds
Logout MySQL session then login again
Take a small test to ensure slow query log is enable
Check sleep on slow query log
Most important:
Using
mysqldumpslow
tool for summarize slow query log filesHow to turn it off?