How to Enable and Optimize MySQL Slow Query Log in DirectAdmin

Priya

Content Writer & Researcher

Last Updated: 22 August 2026
How to Enable and Optimize MySQL Slow Query Log in DirectAdmin
πŸ–₯️

Is a Slow MySQL Database Dragging Down Your DirectAdmin Server?

Database performance issues are one of the hardest problems to self-diagnose on shared hosting servers. CloudHouse's team handles slow query analysis, index optimisation, and MariaDB tuning for DirectAdmin environments β€” so your sites stay fast for every client.

πŸ–₯️12,400+PCs Fixed
⭐4.9β˜…Google Rating
⚑<15 minAvg. Response
πŸ›‘οΈISO 27001Certified

When a DirectAdmin-managed server starts slowing down and PHP pages take seconds to load, MySQL slow queries are often the culprit β€” but they're invisible unless you've turned on slow query logging. DirectAdmin doesn't enable this by default, and the MariaDB configuration file is easy to overlook behind the panel's interface. This guide shows you exactly how to enable the slow query log, read it, identify the queries that are killing your server's performance, and tune MariaDB/MySQL to fix them.

Why MySQL Slow Queries Hurt Shared Hosting Performance

On a DirectAdmin server running dozens of WordPress or WooCommerce sites, a single unoptimised database query can consume significant CPU and I/O. Because MySQL is shared across all hosted accounts, one slow query from one website slows down every other site on the same server. Common causes of slow queries include:

  • Missing indexes: Queries that perform full-table scans instead of using an index
  • Oversized InnoDB buffer pool: MariaDB reading frequently-accessed data from disk instead of RAM
  • Temporary tables spilling to disk: Complex GROUP BY or ORDER BY queries generating large temp tables
  • High connection counts: Too many simultaneous connections causing query queuing
  • Legacy MyISAM tables: Older databases using table-level locking instead of row-level (InnoDB)

πŸ’‘ None of these worked? Skip the guesswork.

Get Expert Help β†’

Step 1: Locate the MariaDB Configuration File in DirectAdmin

DirectAdmin uses MariaDB (a drop-in MySQL replacement) on most modern installations. The main configuration file is at /etc/my.cnf or /etc/mysql/my.cnf, with server-level overrides in /etc/my.cnf.d/.

1Find which config file is active:
mysql --help | grep "Default options" -A 5

This shows the list of configuration files MariaDB reads, in order. The last file listed takes precedence.

2Check the current MariaDB version and confirm it's running:
mysql --version
systemctl status mariadb
3Open /etc/my.cnf as root:
nano /etc/my.cnf
4Add or uncomment these lines under the [mysqld] section:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 1
log_queries_not_using_indexes = 1
min_examined_row_limit = 100

Explanation of each setting:

  • slow_query_log = 1 β€” enables the slow query log
  • slow_query_log_file β€” file path where slow queries are recorded
  • long_query_time = 1 β€” log any query taking longer than 1 second (adjust lower to 0.5 for stricter monitoring)
  • log_queries_not_using_indexes = 1 β€” also log queries that skip indexes, even if they're fast
  • min_examined_row_limit = 100 β€” avoid logging tiny queries that happen to be slow but process very few rows
5Create the log directory and file with correct permissions:
mkdir -p /var/log/mysql
touch /var/log/mysql/slow-query.log
chown mysql:mysql /var/log/mysql/slow-query.log
6Restart MariaDB to apply changes:
systemctl restart mariadb
7Verify logging is active:
mysql -u root -e "SHOW VARIABLES LIKE 'slow_query%';"
mysql -u root -e "SHOW VARIABLES LIKE 'long_query_time';"
8Connect to MariaDB and enable at runtime:
mysql -u root
SET GLOBAL slow_query_log = 'ON';
SET GLOBAL slow_query_log_file = '/var/log/mysql/slow-query.log';
SET GLOBAL long_query_time = 1;
SET GLOBAL log_queries_not_using_indexes = 1;
EXIT;

Note: Runtime changes do not persist through a restart. Always add them to /etc/my.cnf as well.

9Show the top 10 slowest queries by average time:
mysqldumpslow -s at -t 10 /var/log/mysql/slow-query.log
10Show the top 10 most frequently logged queries:
mysqldumpslow -s c -t 10 /var/log/mysql/slow-query.log

The output groups similar queries together and shows execution count, average time, and total time β€” making it easy to spot which queries are causing the most cumulative load.

11Use pt-query-digest for detailed analysis (install if needed):
yum install percona-toolkit -y
pt-query-digest /var/log/mysql/slow-query.log | head -100

Percona Toolkit's pt-query-digest provides a more detailed breakdown including percentile response times, query frequency, and the actual database and table being queried.

12Run EXPLAIN on the slow query:
EXPLAIN SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 10;

In the output, look for:

  • type: ALL β€” this means a full table scan (bad β€” add an index)
  • rows: β€” the estimated number of rows examined; higher is slower
  • Extra: Using filesort β€” the ORDER BY cannot use an index and must sort in memory or on disk
13Add an index to fix full table scans:
ALTER TABLE wp_posts ADD INDEX idx_post_type_status_date (post_type, post_status, post_date);
14Check current buffer pool size:
mysql -u root -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
15Set the buffer pool to 50-70% of total RAM. For a server with 8GB of RAM, set it to 4-5GB:

[mysqld]
innodb_buffer_pool_size = 4G
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 2
innodb_flush_method = O_DIRECT
query_cache_type = 0
query_cache_size = 0

Notes on these settings:

  • innodb_flush_log_at_trx_commit = 2 β€” improves write performance at the cost of up to 1 second of data loss in a crash (acceptable for most shared hosting)
  • query_cache_type = 0 β€” disable the legacy query cache (deprecated in MariaDB 10.5+, causes mutex contention)

16. Restart MariaDB after editing my.cnf and verify the new settings:

systemctl restart mariadb
mysql -u root -e "SHOW VARIABLES LIKE 'innodb_buffer_pool_size';"
17Download and run MySQLTuner:
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl -O mysqltuner.pl
perl mysqltuner.pl --user root

MySQLTuner will highlight:

  • Tables that haven't been converted to InnoDB
  • Whether the buffer pool is sized appropriately for your workload
  • Temporary table overflow (indicating memory settings need adjustment)
  • Connection count vs max_connections setting

Apply recommended changes to /etc/my.cnf and restart. For help managing MariaDB performance across a large DirectAdmin environment, CloudHouse's server management service includes database tuning as standard.

Conclusion

MySQL slow query logging is the most reliable way to diagnose database performance issues on a DirectAdmin server. By enabling the slow query log, analyzing it with mysqldumpslow or pt-query-digest, using EXPLAIN to find missing indexes, and tuning the InnoDB buffer pool, you can dramatically reduce page load times across all hosted sites. The key is to enable logging first, collect real data from your workload, and then tune based on what you actually observe β€” not guesswork.

Get the Free Linux Server Admin Cheatsheet (PDF)

Essential commands for server management, networking, and troubleshooting β€” all on one printable page.

Running Linux servers? Let us manage them for you.

Our Managed Linux Server plans cover updates, security hardening, monitoring, and 24/7 incident response β€” so your servers stay up and your team stays focused.

  • Proactive OS patching and security updates
  • 24Γ—7 monitoring with instant alerting
  • Backup configuration and disaster recovery
  • Dedicated Linux engineers on call
See Pricing Plans β†’

What our customers say

β€œOur production server went down at 2 AM. CloudHouse had it back online in under 20 minutes. Incredible response time.”

Arun S.

CTO, SaaS Startup

β€œThey migrated our entire infrastructure from Ubuntu 18 to 22 with zero downtime. Couldn't have asked for better.”

Deepak N.

DevOps Lead

Frequently Asked Questions

Edit /etc/my.cnf and add these lines under [mysqld]: slow_query_log = 1, slow_query_log_file = /var/log/mysql/slow-query.log, long_query_time = 1, and log_queries_not_using_indexes = 1. Then restart MariaDB with: systemctl restart mariadb. Verify it's active by running: mysql -u root -e "SHOW VARIABLES LIKE 'slow_query%';"

Need this done for you?

Server Management Service

Managed Linux and Windows servers: monitoring, patching, security and 24/7 support.

Learn more

Book your free 15-minute diagnosis

A certified technician will call you back within 15 minutes during business hours.

Share this article

Leave a Comment

Comments (0)

Loading comments...