A customer reports their site is slow at random. You ask for the MySQL slow query log; they don’t have one because cPanel doesn’t enable it by default and the UI gives you no way to turn it on. Most operators then SSH in, append two lines to /etc/my.cnf, restart MySQL, and walk away. Twelve hours later the disk is full because nothing rotates the file and long_query_time was left at the default that captures almost every query under load. Enabling the log is a 30-second job; doing it survivably takes a few more.
What’s happening
slow_query_log is a global MySQL/MariaDB setting that writes to a file or to the mysql.slow_log table. cPanel does not put this in the UI because the per-account php-fpm slow log and the MySQL slow log address different questions, and surfacing both would confuse most users. Without rotation, a busy host writes hundreds of MB per hour. With the default long_query_time = 10, you catch reporting queries and miss the 0.5-second SELECT that runs a hundred times per page load — see the separate article on reading the slow log to understand which threshold to pick.
How to verify
mysql -e "SHOW VARIABLES LIKE 'slow_query_log%'"
mysql -e "SHOW VARIABLES LIKE 'long_query_time'"
mysql -e "SHOW VARIABLES LIKE 'log_output'"
ls -lh /var/lib/mysql/*slow* /var/log/mysql/slow.log 2>/dev/null
df -h /var/lib/mysql
The first three return the current state — log on/off, threshold, destination. The ls confirms which file the log is actually going to (cPanel hosts vary: /var/lib/mysql/$(hostname)-slow.log is the default on MariaDB, /var/log/mysql/slow.log if someone explicitly set it). The df is the one most often skipped — knowing how much disk you have before you turn on logging is the difference between debugging and recovery.
The fix
- Choose a threshold first. For a typical cPanel WordPress host,
long_query_time = 0.5captures the queries that matter without flooding. For a busy WooCommerce or Magento host, start at1.0and adjust down once you have a baseline. - Set it persistently in
/etc/my.cnf.d/cpanel.cnf(cPanel’s preferred override path — edits to/etc/my.cnfget overwritten by some cpupgrade actions):
Create[mysqld] slow_query_log = 1 slow_query_log_file = /var/log/mysql/slow.log long_query_time = 0.5 log_slow_admin_statements = 0 log_queries_not_using_indexes = 0/var/log/mysqlandchown mysql:mysql /var/log/mysqlfirst — MySQL will refuse to start if it can’t write the file. - Apply without a restart to validate before persisting:
SET GLOBAL slow_query_log = 1; SET GLOBAL long_query_time = 0.5; SET GLOBAL slow_query_log_file = '/var/log/mysql/slow.log';. If the host is healthy after 10 minutes of logging, the config-file change is safe. - Add logrotate. Drop this into
/etc/logrotate.d/mysql-slow:
Without/var/log/mysql/slow.log { daily rotate 7 missingok compress delaycompress notifempty postrotate mysql -e "FLUSH SLOW LOGS" endscript }FLUSH SLOW LOGS, MySQL keeps writing to the renamed file and the newslow.logstays empty. - Turn it off when you’re done. Slow query logging is a debugging tool, not a permanent setting. Leave it running for 24 hours, run
pt-query-digeston the file, then disable:SET GLOBAL slow_query_log = 0. If the host needs continuous query observability, that’s a job for an APM agent, not a 7GB rotating text file.
For environments where MySQL profiling is a recurring need, Stack Harbor’s environment management team ships a scripted slow-log session that captures a representative window, digests it, and disables itself.