To set and enable the slow query log in MariaDB, follow these steps:
Open the MariaDB configuration file (/etc/my.cnf
) in a text editor.
Add the following lines to the file to enable the slow query log:
[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
Replace /var/log/mysql/mysql-slow.log
with the path and filename that you want to use for the slow query log.
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.
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.
Save and close the configuration file.
restart MariaDB service.