How To Enable Slow Query Log for MySQL

Enable Slow Query Log for MySQL

In this tutorial, we will show you how to enable slow query log for MySQL on Linux systems. MySQL has built-in functionality that allows you to log SQL queries to a file, You can enable the full SQL queries logs to a file or only slow running queries log. It is easy for us to troubleshoot/ debug the SQL statement if SQL queries log enable, The slow query log is used to find queries that take a long time to execute and are therefore candidates for optimization. We assume that you already have MySQL installed on the Linux system with administrative privileges and we assume that you already have a small amount of knowledge on MySQL.

In order to enable slow query logs for MySQL on your system, you would need to do the following.

Enable Slow Query Log for MySQL

Step 1. Edit the /etc/my.cnf file with your favorite text editor.

 Step 2. Once you have your my.cnf file open, add the following line under the “[mysqld]” section.

 Step 3. Then create the file slow-queries.log. You can have the file in any spot you wish, as long as you define the path in your my.cnf.

Step 4. After that, restart MySQL service. Enter the following command:

Congratulations! You have successfully enabled slow query log on MySQL. Thanks for using this tutorial to enable a slow query log on MySQL in the Linux system. For additional help or useful information, we recommend you to check the official MySQL website.

MySQL Configuration Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “MySQL Configuration”, starting from $10 (Paypal payment). Please contact us to get a best deal!