How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: How to Check Which MySQL Database or User Is Using the Most CPU
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > Server Management > How to Check Which MySQL Database or User Is Using the Most CPU
Server Management

How to Check Which MySQL Database or User Is Using the Most CPU

how7o
By how7o
Last updated: May 10, 2026
8 Min Read
MySQL top CPU usage — PROCESSLIST snapshot and performance_schema digest
SHARE

When top shows MySQL hogging a server, mysql top cpu usage inside the MySQL shell tells you which database, user, or query is actually responsible. SHOW FULL PROCESSLIST is the one-second snapshot; performance_schema gives you cumulative stats over time. Together they let you trace a CPU spike back to the exact site, user, or query pattern to fix.

Contents
  • TL;DR
  • Snapshot: SHOW FULL PROCESSLIST
  • Historical view: performance_schema
  • Matching threads to sites
  • Secondary diagnostic: SHOW OPEN TABLES
  • From diagnosis to fix
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on MySQL 8.0 and MariaDB 10.11. Originally published 2022-06-08, rewritten and updated 2026-04-23.

TL;DR

-- Connect as root via SSH
mysql -u root -p

-- Snapshot of what's running right now
SHOW FULL PROCESSLIST;

-- Top 10 query patterns by cumulative time (MySQL 8 / MariaDB 10.5+)
SELECT
    SUBSTRING(digest_text, 1, 100) AS query,
    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;

Snapshot: SHOW FULL PROCESSLIST

SHOW FULL PROCESSLIST;

Returns a row per thread. The columns that matter:

  • User — MySQL user running the query. Match this against your apps.
  • db — database the query is touching. Match this against your app configs.
  • Command — Query means actively working; Sleep means idle connection.
  • Time — seconds the thread has been in its current state. Long times = long queries = CPU hogs.
  • State — Sending data, Copying to tmp table, Sorting result are usually CPU-bound.
  • Info — the actual SQL (truncated unless you used FULL).

Run it three or four times in quick succession. Anything that shows up every time is the real problem; a one-off Time: 12 that disappears on the next check is just a slow query passing through.

mysql top cpu usage — PROCESSLIST snapshot plus performance_schema historical digest

Historical view: performance_schema

SELECT
    SUBSTRING(digest_text, 1, 100) AS query,
    schema_name                     AS db,
    count_star                      AS exec_count,
    ROUND(sum_timer_wait / 1e12, 2) AS total_seconds,
    ROUND(avg_timer_wait / 1e9,  2) AS avg_ms
FROM performance_schema.events_statements_summary_by_digest
ORDER BY sum_timer_wait DESC
LIMIT 20;

This is the top 20 query digests (similar queries grouped) by cumulative time since the server started. Unlike PROCESSLIST, it sees patterns — a query that runs 10,000 times at 50ms each isn’t visible in a snapshot but dominates the cumulative list. The schema_name tells you which database.

performance_schema is enabled by default on MySQL 5.6.6+ and MariaDB 10.0.5+. If the query errors with “Unknown table,” check SHOW VARIABLES LIKE 'performance_schema'; — if OFF, enable it in my.cnf and restart (see restart MariaDB).

Matching threads to sites

If your server hosts multiple sites, each should have its own MySQL user (see creating users and granting privileges). Then:

# In the site's config:
#   WordPress: wp-config.php → DB_USER, DB_NAME
#   Laravel:   .env          → DB_USERNAME, DB_DATABASE

Cross-reference the PROCESSLIST User + db columns against each site’s config. The CPU-burning threads belong to whichever site owns that user/db pair. If every site shares root, you can’t distinguish them — which is a good reason to fix that first.

Secondary diagnostic: SHOW OPEN TABLES

SHOW OPEN TABLES WHERE In_use > 0;

Lists tables currently locked or being read. Not a CPU-usage tool, but useful alongside PROCESSLIST: if a site’s table keeps showing up as in-use, its queries are likely the hot ones. Treat as supporting evidence, not primary diagnostic.

From diagnosis to fix

-- Once you've identified the slow query, explain it
EXPLAIN SELECT ... FROM ... WHERE ...;

-- Look for:
--   type: ALL            -> full table scan, needs an index
--   rows: 1000000        -> scanning too much data
--   Using temporary      -> creates a temp table (slow)
--   Using filesort       -> does an extra sort pass

Add an index on the column in the WHERE or JOIN, re-run EXPLAIN until type shows something other than ALL. For WordPress, the most common fix is adding a composite index on (post_id, meta_key) in wp_postmeta. For Laravel, checking that your Eloquent relationships aren’t triggering N+1 queries (use with('relation')).

Frequently asked questions

What’s the fastest mysql top cpu usage check?

SHOW FULL PROCESSLIST; inside a root MySQL session. It lists every currently-running thread with its user, database, state, time, and query. The threads with high Time values and states like Sending data or Copying to tmp table are the ones burning CPU. Run it a few times in quick succession — anything that shows up repeatedly is the real hog.

Can I see historical CPU use, not just the current second?

Yes — enable the performance schema’s statements summary: SELECT digest_text, count_star, sum_timer_wait FROM performance_schema.events_statements_summary_by_digest ORDER BY sum_timer_wait DESC LIMIT 10;. Shows the top 10 query shapes (not individual queries — similar queries are grouped by digest) by total time since server start. Better than PROCESSLIST for diagnosing patterns.

How do I identify the website causing MySQL CPU spikes?

Match the User and db columns from SHOW PROCESSLIST against your WordPress/Laravel config files — wp-config.php‘s DB_USER + DB_NAME, or .env‘s DB_USERNAME + DB_DATABASE. Each site typically has its own user/db pair, so PROCESSLIST lines tagged with wp_myblog on database wp_myblog point straight to that site.

Is SHOW OPEN TABLES useful here?

Only indirectly — it shows what’s in the table cache, not active CPU. It can hint at which tables are hot, but PROCESSLIST and performance_schema are the right tools for ‘who’s burning the CPU right now.’ Treat OPEN TABLES as supporting evidence, not a primary diagnostic.

What do I do once I’ve found the slow query?

EXPLAIN SELECT ... the query, look for type: ALL (full table scan) or big rows estimates. Usually it needs an index. On WordPress, common culprits are wp_options lookups that skip autoload = 'yes' filtering, or wp_postmeta joins without the meta_key index. Fix the index, re-run EXPLAIN until the query uses one. If the query itself is bad architecture (SELECT * across millions of rows), refactor.

Related guides

  • How to Create Users and Grant Privileges in MySQL 8 — per-site users for clean PROCESSLIST attribution.
  • How to Restart the MariaDB Server on Linux — after enabling performance_schema.
  • How to Troubleshoot MariaDB Not Starting — for the worst-case scenario.
  • How to Prepare a %LIKE% SQL Statement in WordPress — application-side SQL patterns.

References

MySQL SHOW PROCESSLIST: dev.mysql.com/doc/refman/8.0/en/show-processlist. performance_schema digest: dev.mysql.com/doc/refman/8.0/en/performance-schema-statement-digests.

TAGGED:mariadbmysqlperformancetroubleshooting

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article MariaDB not starting — six-step triage from logs to stale PID How to Troubleshoot MariaDB Not Starting
Next Article MySQL combine columns into string — CONCAT and CONCAT_WS How to Combine Multiple Columns into One String in MySQL
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

WooCommerce product view counter — meta-based counter with increment and display hooks
Web Development

How to Display a Product View Counter in WooCommerce Without a Plugin

7 Min Read
Installed Discourse on AlmaLinux
Server Management

How I Installed Discourse on AlmaLinux (Docker Method, Step-by-Step)

6 Min Read
Laravel Eloquent orderBy — code snippet sorting posts by id descending with arrow icons
Web Development

How to Use orderBy in Laravel Eloquent (with Examples)

6 Min Read
MariaDB restart on Linux — systemctl restart mariadb
Server Management

How to Restart the MariaDB Server on Linux

6 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?