Quantcast
Channel: Welcome To TechBrothersIT
Viewing all articles
Browse latest Browse all 1876

What is Slow Query Logging in MairaDB or MySQL and How to Enable Slow Query Log in MySQL or MairaDB

$
0
0

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 entries

slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql/slow-query.log
log_queries_not_using_indexes=1

For Galera Cluster : 

Go to /etc/my.cnf.d/server.cnf file and add below 

slow_query_log = 1
long_query_time = 1
slow_query_log_file = /var/log/mysql/slow-query.log
log_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




Viewing all articles
Browse latest Browse all 1876

Trending Articles