DirectAdmin MySQL Slow Queries: How to Diagnose and Fix Database Performance Issues

Priya

Content Writer & Researcher

Last Updated: 3 August 2026
DirectAdmin MySQL Slow Queries: How to Diagnose and Fix Database Performance Issues
πŸ–₯️

Is MySQL Slowing Down Your DirectAdmin Server?

Our server management team will audit your MySQL configuration, identify slow queries, tune my.cnf to match your actual RAM, and add missing indexes β€” all without downtime. Book a free 15-minute diagnosis today.

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

If sites on your DirectAdmin server are timing out and top or htop shows MySQL or MariaDB pegging the CPU, you have a directadmin mysql slow queries fix problem that needs resolving before more clients escalate. This guide walks you through diagnosing the exact bad queries, safely tuning my.cnf to match your available RAM, and adding missing indexes β€” all without taking your live server offline.

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

Get Expert Help β†’

How to Confirm MySQL Is Causing Slow Sites on DirectAdmin

Before touching any configuration, verify that MySQL is genuinely the bottleneck and not something else (PHP, disk I/O, network).

1Check real-time process load

Run top and press M to sort by memory, then P to sort by CPU. Look for mysqld or mariadbd consistently above 80% CPU or consuming the majority of available RAM.

top -b -n1 | grep -i mysql
2Check active queries inside MySQL

Log into MySQL as root and run the process list. Queries in the Copying to tmp table, Sorting result, or Locked state are the usual suspects:

mysql -u root -p -e "SHOW FULL PROCESSLIST;"
3Check global status counters

These counters reveal accumulated pressure since the last restart:

mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Slow_queries';"
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Created_tmp_disk_tables';"
mysql -u root -p -e "SHOW GLOBAL STATUS LIKE 'Handler_read_rnd_next';"
  • Slow_queries > 0 β€” confirms slow query activity even if the log is not yet enabled
  • Created_tmp_disk_tables high β€” queries spilling temp tables to disk, a major drag
  • Handler_read_rnd_next very high β€” full table scans happening constantly
4Check disk I/O to rule out storage bottleneck
iostat -x 1 5

If %iowait stays above 20% and MySQL CPU is also high, you have both a query problem and a hardware constraint β€” fix the queries first, then consider SSD or increased RAM.

1Find and open my.cnf
# CentOS / AlmaLinux / CloudLinux (most common with DirectAdmin)
nano /etc/my.cnf

# Debian / Ubuntu
nano /etc/mysql/my.cnf
2Add slow query log directives under [mysqld]

Add these lines inside the [mysqld] section. If the section does not exist, create it at the top of the file:

[mysqld]
slow_query_log          = 1
slow_query_log_file     = /var/log/mysql/mysql-slow.log
long_query_time         = 1
log_queries_not_using_indexes = 1
min_examined_row_limit  = 100
  • long_query_time = 1 β€” logs any query taking over 1 second. Start at 2 for very busy servers to reduce noise, then lower to 0.5 once you've fixed the worst offenders.
  • log_queries_not_using_indexes = 1 β€” catches full table scans even on fast queries.
  • min_examined_row_limit = 100 β€” avoids logging trivial single-row lookups.
3Create the log file and set permissions
mkdir -p /var/log/mysql
touch /var/log/mysql/mysql-slow.log
chown mysql:mysql /var/log/mysql/mysql-slow.log
4Reload MySQL without dropping connections (zero-downtime)

On DirectAdmin servers, use systemctl reload rather than restart whenever possible β€” this re-reads the config without killing existing connections:

# MariaDB (most DirectAdmin installs)
systemctl reload mariadb

# Or MySQL
systemctl reload mysqld

If reload is not supported by your version, a restart is required. Schedule it during off-peak hours:

systemctl restart mariadb
5Enable the log dynamically (no restart needed)

You can also switch on the slow query log live without touching my.cnf β€” useful for a quick diagnostic session:

mysql -u root -p -e "SET GLOBAL slow_query_log = 'ON';"
mysql -u root -p -e "SET GLOBAL long_query_time = 1;"
mysql -u root -p -e "SET GLOBAL slow_query_log_file = '/var/log/mysql/mysql-slow.log';"

Note: dynamic changes are lost on the next MySQL restart, so always persist settings in my.cnf.

1Get the top 10 slowest queries by total time
mysqldumpslow -s t -t 10 /var/log/mysql/mysql-slow.log
2Get the top 10 by execution count (high frequency)
mysqldumpslow -s c -t 10 /var/log/mysql/mysql-slow.log
3Understand the output fields
  • Count β€” how many times this query pattern ran during the log window
  • Time β€” average and max execution time
  • Lock β€” average lock wait time (high lock times point to table-level locking or InnoDB deadlocks)
  • Rows β€” rows examined vs rows sent (a ratio of 10,000:1 screams for an index)
  • Query β€” the normalized SQL pattern (literals replaced with N or S)
4Use EXPLAIN to understand query execution

Take the worst query from the log and prepend EXPLAIN:

EXPLAIN SELECT * FROM wp_posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 10;

Watch for type: ALL (full table scan) and key: NULL (no index used). These are the columns you need to index.

1Identify tables needing indexes from EXPLAIN output

Any EXPLAIN showing type: ALL on a large table with no key is a candidate. The columns in your WHERE, ORDER BY, and JOIN ON clauses should be indexed.

2Add indexes via MySQL CLI
-- Example: WordPress site with slow post queries
ALTER TABLE wp_posts ADD INDEX idx_post_status_type_date (post_status, post_type, post_date);

-- Example: WooCommerce order meta slow lookup
ALTER TABLE wp_postmeta ADD INDEX idx_meta_key_value (meta_key, meta_value(20));

Use ALTER TABLE ... ADD INDEX rather than CREATE INDEX β€” both are equivalent but the ALTER form is standard for MySQL/MariaDB.

3Use phpMyAdmin for visual index management

In DirectAdmin, navigate to Extra Features β†’ phpMyAdmin. Select the database β†’ select the table β†’ click the Structure tab β†’ scroll to the Indexes section. You can add, edit, and remove indexes through the GUI without writing SQL.

4Run OPTIMIZE TABLE to reclaim fragmented space

After deleting large numbers of rows or after heavy insert/delete cycles, InnoDB tables accumulate fragmentation. OPTIMIZE TABLE rebuilds the table and its indexes:

-- In phpMyAdmin: select tables β†’ Operations β†’ Optimize table
-- Or via CLI:
OPTIMIZE TABLE wp_posts;
OPTIMIZE TABLE wp_postmeta;

Note: OPTIMIZE TABLE on InnoDB acquires a metadata lock but does NOT block reads/writes for the entire duration on MariaDB 10.5+ (it uses online DDL). On older versions, run it during off-peak hours.

5Use mysqlcheck to optimize all databases at once
mysqlcheck -u root -p --optimize --all-databases
6Enable performance_schema for deeper analysis

MariaDB 10.5+ includes a lightweight Performance Schema. The events_statements_summary_by_digest table shows the top SQL patterns by total latency β€” more detailed than the slow query log:

SELECT DIGEST_TEXT, COUNT_STAR, ROUND(SUM_TIMER_WAIT/1e12, 2) AS total_seconds
FROM performance_schema.events_statements_summary_by_digest
ORDER BY SUM_TIMER_WAIT DESC
LIMIT 10;

If your shared hosting clients are running WordPress, WooCommerce, or Magento, the most common slow queries are on wp_options (missing autoload index), wp_postmeta, and session tables. Fixing these three tables alone typically cuts MySQL CPU by 30–50% on a busy DirectAdmin shared server.

For ongoing expert database tuning and server-level optimisation, the team at CloudHouse server management service can audit your DirectAdmin stack, implement safe configuration changes, and monitor MySQL health 24/7 β€” without any downtime to your live sites.

FAQs

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

On CentOS, AlmaLinux, and CloudLinux (the most common DirectAdmin base OSes), the main MySQL/MariaDB config is at /etc/my.cnf. On Debian/Ubuntu-based DirectAdmin installs it may be at /etc/mysql/my.cnf or /etc/mysql/mariadb.conf.d/50-server.cnf. Run 'mysqld --help --verbose 2>&1 | grep -A1 "Default options"' to see the exact search order on your server.

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