How to set and enable MariaDB slow query log

How to set and enable MariaDB slow query log

To set and enable the slow query log in MariaDB, follow these steps:

  1. Open the MariaDB configuration file (/etc/my.cnf) in a text editor.

  2. Add the following lines to the file to enable the slow query log:

refer‮l:ot ‬autturi.com
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log_queries_not_using_indexes = 1
  1. Replace /var/log/mysql/mysql-slow.log with the path and filename that you want to use for the slow query log.

  2. Set the long_query_time parameter to the number of seconds that a query must take to be considered slow and logged. For example, a value of 1 will log all queries that take more than 1 second to run.

  3. Set the log_queries_not_using_indexes parameter to 1 to log queries that do not use indexes. This can help identify inefficient queries that may benefit from the use of indexes.

  4. Save and close the configuration file.

  5. restart MariaDB service.

Created Time:2017-10-29 22:08:37  Author:lautturi