Slow Query Log
⦁ Slow query log stores the information for querys that took long time to run.Enable Slow Query Logging :
For Stand Alone :
Go to /etc/my.cnf and add below entriesslow_query_log = 1long_query_time = 1slow_query_log_file = /var/log/mysql/slow-query.loglog_queries_not_using_indexes=1
For Galera Cluster :
Go to /etc/my.cnf.d/server.cnf file and add below
slow_query_log = 1long_query_time = 1slow_query_log_file = /var/log/mysql/slow-query.loglog_queries_not_using_indexes=1
Check Current values :
Login to MySQL or MariaDB and run below queries to check the current settings of slow query logging
SHOW VARIABLES LIKE 'slow_query_log';
SHOW VARIABLES LIKE 'long_query_time';
SHOW VARIABLES LIKE 'slow_query_log_file';
Enable General Log for Table :
To write logs into tables, the log_output server system variable is used. Allowed values are FILE, TABLE and NONE. It is possible to specify multiple values, separated with commas, to write the logs into both tables and files. NONE disables logging and has precedence over the other values.SET GLOBAL log_output = 'FILE,TABLE';
If General log is active for table, you can query the table to see the information.
SELECT * FROM mysql.slow_log;
Video Demo : How to capture long running queries in MySQL or MariaDB