Cloud House Technologies Logo
CloudHouse Technologies
HomeServicesProjectsBlogAbout UsCareersContact UsLogin
    Cloud House Technologies Logo
    CloudHouse Technologies
    HomeServicesProjectsBlogAbout UsCareersContact UsLogin

    How to Enable and Optimize MySQL Slow Query Log in DirectAdmin

    Priya

    Content Writer & Researcher

    Last Updated: 20 June 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.

    🔧 Book Free DiagnosisCall NowWhatsApp
    🖥️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%';"

    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...

    Need Help Optimising MySQL on DirectAdmin?

    Slow databases affect every site on your server. Our team enables slow query logging, analyses your worst-performing queries, and tunes MariaDB for your exact workload — without downtime or guesswork.

    Call Now — FreeWhatsApp Us

    Why CloudHouse?

    • ISO 27001:2022 certified
    • 12,400+ devices supported
    • 4.9★ on Google
    • Sub-15-minute response

    CloudHouse Technologies

    Innovative cloud solutions for modern businesses. We deliver cutting-edge technology with exceptional service.

    Contact Us

    CloudHouse Technologies Pvt.Ltd
    Special Economic Zone(SEZ),
    Infopark Thirissur,4B-15,
    Indeevaram,Nalukettu Road,
    Koratty, Kerala, India-680308
    0480-27327360
    info@cloudhousetechnologies.com

    Quick Links

    • Our Services
    • Gold Loan Software
    • About Us
    • Contact
    • Terms and Conditions
    • Privacy Policy
    ISO27001:2022
    Certified

    © 2026 CloudHouse Technologies Pvt.Ltd. All rights reserved.

    Back to top