How To Enable Slow Query In MySQL
If you know how to enable slow query in MySQL it’s easy to setup. It can help you analyse the database server response time. By default, slow_query_log is off in MySQL 5.5.
There are two ways of checking slow_query_log is enabled or not.
Method 1 : show variables like “slow_query_log”;
Method 2 : mysqladmin var |grep log_slow_queries
As you can see slow_query_log is off So let’s enable it by globally thorough command in MySQL if you want to enable it permanent you will have to put this in my.cnf file.
SET GLOBAL slow_query_log = 1;
SET GLOBAL slow_query_log = 0;
You need to Set slow log query file path
SET GLOBAL slow_query_log_file = ‘/var/log/mariadb/my-slow.log’;
Now Check slow query will be ON
Add permanent in vim /etc/my.cnf
As you can see, By Default slow query log file is located at /var/lib/mysql/mysql-slow.log
Now restart the service,
YouTube Link :