How to enable MySQL slow query log
The slow query log consists of SQL statements that take more than long_query_time seconds to execute and require at least min_examined_row_limit rows to be examined.
Here are the steps to enable MySQL slow query log permanently:
Login to server and edit MySQL configuration file
vi /etc/my.cnf
Add the following:
# Slow query log slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log # Log queries longer than 2 seconds long_query_time = 2 # Log queries not using indexes log_queries_not_using_indexes = 1
Create the log directory and give it to the database user:
mkdir -p /var/log/mysql && chown mysql:mysql /var/log/mysql
Restart the database server (MariaDB shown; use mysqld on MySQL). To switch the log on without a restart, run SET GLOBAL slow_query_log = 1; as well.
systemctl restart mariadb
From the EuroVPS FAQ.
More in how toYour next infrastructure partner
Still have
a question?
Tell us what you are trying to do. An engineer will read it and reply.
+357 222 32280
who will look after your infrastructure.
Let’s start with your setup.
A little context helps us start the right conversation.
