How to set and enable MariaDB slow query log
To enable and set up the slow query log in MariaDB, you need to modify the configuration file my.cnf and restart the MariaDB service.
Here are the steps to enable the slow query log in MariaDB:
- Open the
my.cnfconfiguration file:
sudo nano /etc/my.cnf- Add the following lines to the configuration file:
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.logrnlong_query_time = 2
log_queries_not_using_indexes = 1- The
slow_query_logdirective is used to enable the slow query log. - The
slow_query_log_filedirective is used to specify the location where the log file will be stored. - The
long_query_timedirective sets the threshold for what constitutes a slow query. In this example, a query that takes more than 2 seconds will be logged. - The
log_queries_not_using_indexesdirective is used to log queries that don't use indexes.
- Save and close the file.
- Restart the MariaDB service:
sudo systemctl restart mariadb- To verify that the slow query log is working, you can check the log file at
/var/log/mysql/mariadb-slow.log. If the log is not being created, check the MariaDB error log for any issues.
