How To Enable Slow Query In MySQL Server In Linux

If you know how to enable slow query in MySQL it’s easy to setup. It can help you analyze the database server response time. you can enable and check a slow query log when you configure with a single command in MySQL.

By default, slow_query_log is off in MySQL 5.5. This helps you to find out which query is taking a long time to execute than the given threshold.

Check Out: How To Change User Password In MySQL Server 5.x On CentOS

How To Enable Slow Query In MySQL:

We can achieve these either by adding a permanent setting or temporary basis without restart the MySQL service. There are two ways of checking slow_query_log is enabled or not.

Method 1 : show variables like “slow_query_log”;

how to enable slow

Method 2 : mysqladmin var |grep log_slow_queries

enable slow query log

As you can see slow_query_log is “off“. So let’s enable it by the globally thorough command in MySQL if you want to enable it permanent you will have to put this in my.cnf file.

Check Out: MySQL Database Backup In GZ Format On Linux 7

We can use the below command to Enable on the server for temporary. 

SET GLOBAL slow_query_log = 1;

configure slow query log

In a similar way, we can use the below command For Disable on the server.

SET GLOBAL slow_query_log = 0;

You need to Set the slow log query file path using the command line for temporary.

SET GLOBAL slow_query_log_file = '/var/log/mariadb/my-slow.log';

check slow query log

Check Out: Install MySQL 5.6 Database Server Using Repository In Linux

Now Check slow query will be “ON“. 

show variables like "slow_query_log";

enable slow query log

if you need to keep those settings permanent, we have to add those parameters in my.cnf file and restart the MySQL service.

vim /etc/my.cnf

Check Out: Could Not Find Driver With Class Name: com.mysql.jdbc

As you can see, By Default, the slow query log file is located at /var/lib/mysql/mysql-slow.log

Now restart the MySQL service to make changes,

YouTube Link:

You’re done.check slow query log configure slow query log check slow query log enable slow query log

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment