Loading Smiley Hoster
Skip to content

Capture slow MySQL queries on a cPanel server

Smiley Hoster Team · · 3 min read
A three-step sequence shows SQL capture, grouping and a controlled test.

If database work is holding up a cPanel website, adding PHP workers can increase the backlog. MySQL’s slow query log offers a more focused starting point: capture a bounded sample and turn it into a testable application change.

1. Plan the capture before enabling it

This procedure targets MySQL 8.0 and requires database administration privileges. Identify the actual engine first; a MariaDB deployment needs settings checked against its own version.

Pick one user action to investigate, such as a product search or report export. Record its domain, database and time window. Save the current server values in an administrative SQL session:

Example
SELECT VERSION();SHOW GLOBAL VARIABLES LIKE 'slow_query_log%';SHOW GLOBAL VARIABLES LIKE 'long_query_time';SHOW GLOBAL VARIABLES LIKE 'log_output';SHOW GLOBAL VARIABLES LIKE 'min_examined_row_limit';

Check storage capacity and access permissions for the selected log location. Query text may contain customer information. Decide who can read it, when collection ends and when the file will be removed.

A named end time matters: an unattended diagnostic log should not become the next storage incident.

2. Collect evidence you can compare

The following is an illustrative temporary capture, not a universal production setting:

Example
SET GLOBAL log_output = 'FILE';SET GLOBAL long_query_time = 2;SET GLOBAL slow_query_log = ON;

Existing application connections may retain their previous session threshold. Confirm that a qualifying slow request from your test actually appears. Also retain the examined-row filter in your investigation record because it affects which statements qualify.

When the window ends, restore the original settings, including the log destination. Preserve an already-enabled logging arrangement used by another administrator instead of blindly switching everything off.

Summarize a protected copy using its actual file path:

Example
mysqldumpslow -s t -t 10 /path/to/slow.logmysqldumpslow -s c -t 10 /path/to/slow.log

Look at repeated patterns as well as costly ones. Avoid starting with unrestricted logging of queries without indexes; it can drown the investigation in additional output.

3. Give the application owner an actionable finding

For each selected pattern, record the database, application identity, observed recurrence and user action that triggers it. Map the database to its hosting account in WHM. The shared MySQL operating-system process does not identify the responsible customer.

Choose one change to evaluate on a test copy: remove a repeated lookup, reshape a query or assess an appropriate index. Do not change server-wide limits solely because a single query was slow.

Repeat the same user action under comparable demand. Compare both website latency and the recurring SQL pattern. Keep a redacted before-and-after finding, then remove sensitive capture files when their retention period ends.

Sources: MySQL — slow query log, MySQL — mysqldumpslow.

Slide 1 of 5: cPanel / MySQL. Find the slow queries behind a slow site. Use a bounded capture to turn database evidence into a testable application change.
Slide 2 of 5: Plan the capture. Set a clear window. For MySQL 8.0 with admin privileges: choose one user action and save current settings. Check log storage and permissions. Set an end time and a deletion date: query text may contain customer information.
Slide 3 of 5: Collect comparable evidence. Confirm the capture works. Verify a qualifying test request appears in the log. Existing connections may keep old thresholds. At the end, restore original settings. Use mysqldumpslow on a protected copy to find costly and repeated patterns.
Slide 4 of 5: Test an application fix. Compare before and after. Map the database to its hosting account in WHM. Test one query, lookup or index change on a test copy. Repeat the same action under comparable demand; compare website latency and the recurring SQL pattern.
Slide 5 of 5: From evidence to action. Make one testable change. Save these steps. Read the full guide for capture settings, connection caveats and cleanup checks.
On social media

See it in our social posts

The key steps of this article, as a carousel. Follow us to catch the next ones.

Did this article answer your question?
Your feedback shapes what we write next.

Your site online today

Free migration* · 30-day refund

Get started* A site under 30 GB, cPanel, WordPress and VPS plans.