How to Enable Slow Query Logging for MySQL Server on Windows and Linux Machine - MySQL DBA Tutorial

What is Slow Query Logging in MySQL Server and How to Enable on Windows and Linux Server


The Slow Query Logging is used to capture the queries which do not use indexes or they execute for long time which is defined by long_query_time. By default the value for long_query_time is 10 seconds.

Slow Query Logging for MySQL in Windows:


If Slow Query Logging is enabled without providing the location for Slow Query log file, then by default location for the Slow Query log will be "C:\ProgramData\MySQL\MySQL Server 8.0\Data" and file name will be "HostName-slow.log".
To make change for Slow Query log file location and name , you can go to my.ini file on below path
"C:\ProgramData\MySQL\MySQL Server 8.0", Look for

slow-query-log=1
slow_query_log_file="HostName-slow.log"
long_query_time=10
Change the value slow-query-log=1 to enable it. if you would like to update the location for file, you can change in slow_query_log_file=Folder Path/SlowQueryLogFile.log


General Query Log File in Linux:

The default location for Slow Query log file for MySQL installed on Linux is /var/lib/MySQL. If you need to make changes to default location and binary file name, you can go to /etc/my.cnf file and update it.
In case of default location, the name of the file will be "HostName-slow.log". You can add below configuration to /etc/my.cnf to enable or disable SlowQuery log.

slow-query-log=1
slow_query_log_file="HostName-slow.log"
long_query_time=10

Once you will make the changes, you will be restarting the MySQL service.

MySQL Logging Tutorial - Slow Query Logging in MySQL on Windows and Linux

1 comment:

  1. I think you can try out the different information related to this. Also check out loom recipe it will provide you related information.

    ReplyDelete