Updated: 11 October 2026 · Applies to: MariaDB 10.11 on Ubuntu 24.04 / Debian 12 (AlmaLinux/Rocky noted)
The slow query log records queries that take longer than a set time, which helps you find what slows a site down. Rotate it so it does not fill the disk. These steps are for MariaDB 10.11 on Ubuntu 24.04 / Debian 12 (paths for AlmaLinux/Rocky are noted).
1. Enable the slow log
Create /etc/mysql/mariadb.conf.d/60-slowlog.cnf (AlmaLinux/Rocky: /etc/my.cnf.d/slowlog.cnf):
[mariadb] slow_query_log = 1 slow_query_log_file = /var/log/mysql/mariadb-slow.log long_query_time = 2
On AlmaLinux/Rocky use /var/log/mariadb/mariadb-slow.log. Restart: systemctl restart mariadb.
2. Rotate it with logrotate
Ubuntu and Debian already rotate /var/log/mysql/*.log in /etc/logrotate.d/mariadb. To rotate the slow log separately (for example daily, keeping 14 days), create /etc/logrotate.d/mariadb-slow and use a different file name or folder so the two rules do not overlap:
/var/log/mysql/slow/mariadb-slow.log {
daily
rotate 14
missingok
notifempty
compress
delaycompress
create 640 mysql adm
postrotate
/usr/bin/mariadb-admin --local flush-slow-log >/dev/null 2>&1 || true
endscript
}
Point slow_query_log_file to that path (create the folder, owned by mysql). Test with logrotate -d /etc/logrotate.d/mariadb-slow (dry run), then logrotate -f /etc/logrotate.d/mariadb-slow.
3. Read the log
mariadb-dumpslow -s t /var/log/mysql/slow/mariadb-slow.log | head -40 # slowest query patterns
Note: On cPanel hosting, manage databases in cPanel with Databases › MySQL® Databases and phpMyAdmin; server-level changes are made by the server administrator.