Databases 4 min read

Why Is My MySQL Site So Slow? Diagnose and Fix High CPU Usage

This guide walks through identifying MySQL CPU overload caused by excessive temporary tables and thread creation, then details configuration tweaks and SQL optimizations—including adjusting tmp_table_size, thread_cache_size, and join/sort buffers—to restore normal performance.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Why Is My MySQL Site So Slow? Diagnose and Fix High CPU Usage

While investigating a website that loaded very slowly, the author logged into the server and used top to see that MySQL was consuming over 100% CPU, confirming it as the bottleneck.

Running SHOW PROCESSLIST revealed many LOCK operations and several "Copying to tmp table" entries, indicating that complex SQL statements were creating excessive temporary tables and blocking other work.

The remediation plan focused on two areas: adjusting MySQL configuration parameters and optimizing the problematic SQL queries.

Configuration changes began with inspecting temporary table usage via SHOW GLOBAL STATUS LIKE 'created_tmp%'; which showed a high created_tmp_disk_tables count, prompting an increase of tmp_table_size and related settings. Thread statistics ( SHOW GLOBAL STATUS LIKE 'Thread%';) showed a large threads_created value, so thread_cache_size was raised. Table cache metrics ( SHOW GLOBAL STATUS LIKE 'open%tables%';) indicated an oversized opened_tables count, leading to a higher table_cache value. Other parameters such as join_buffer_size and sort_buffer_size were also increased from their defaults.

These adjustments were applied in my.cnf, for example:

table_cache = 64<br/>sort_buffer_size = 8M<br/>join_buffer_size = 4M<br/>thread_cache_size = 300<br/>thread_concurrency = 8<br/>tmp_table_size = 246M

For SQL optimization, the author filtered the SHOW PROCESSLIST output to locate the most complex statements, then used EXPLAIN and PROFILE to analyze them, added appropriate indexes, and split large queries into smaller ones.

After completing these steps, MySQL returned to normal operation, and the site’s performance improved, with further SQL and caching refinements planned for the future.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performance tuningmysqlSQL OptimizationServer MonitoringDatabase Configuration
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.