When your WordPress site suddenly starts showing database connection errors or goes completely down with messages like:
-
“Error Establishing a Database Connection”
-
“MySQL Error: Too many connections”
-
“Warning: mysqli::real_connect(): (HY000/1040): Too many connections”
…it usually means your MySQL server has hit its maximum number of allowed connections.
This error can send your entire website offline, affect WooCommerce orders, break your admin panel, and kill your SEO rankings if not fixed immediately. The good news? You can fix it — permanently.
In this guide, you’ll learn:
-
What “MySQL Too Many Connections” means
-
Why it happens on WordPress sites
-
Exact steps to fix it
-
How to optimize MySQL properly
-
Server-level and plugin-level causes
-
How to prevent this from happening again
Let’s dive in.
What Does “MySQL Too Many Connections” Mean?
MySQL runs using a maximum allowed number of simultaneous open connections. This number is controlled by a variable called:
Default value is usually 151 on most hosting environments.
If your WordPress site tries to open more connections than this limit, MySQL responds with:
This means:
-
Your site is receiving more requests than MySQL can handle
-
Some script is opening connections but not closing them
-
A plugin/theme is causing a connection leak
-
Your database server is overloaded
-
Bots or attacks flood your site
Understanding the cause is the first step to fixing it.
Common Causes of “Too Many Connections” in WordPress
Here are the top reasons why WordPress sites hit the MySQL connection limit:
1. High Traffic Surges
If your website gets a sudden spike — maybe from:
-
Viral traffic
-
Google Discover
-
Peak WooCommerce sales
-
Bot traffic
-
DDOS / bad crawlers
— the number of database queries increases sharply, leading to too many connections.
2. Slow or Unoptimized Database Queries
A badly optimized query takes longer to complete, which keeps connections open longer.
Causes include:
-
Poorly coded plugins
-
Custom themes with heavy queries
-
Missing database indexes
-
Large WooCommerce tables
3. Plugins Opening Persistent Connections
Some plugins open database connections but never close them, causing what we call connection leaks.
Examples:
-
Analytics plugins
-
Cache-bypass plugins
-
Broken security plugins
-
Email/logging plugins
4. Poor Hosting Configuration
Cheap shared hosting often keeps MySQL limits low:
-
max_connections too low
-
MySQL buffer pool too small
-
Old MySQL version
-
Misconfigured MariaDB
5. Bot or Spam Traffic Overloading the App
Bots can generate 1000s of requests/minute, causing MySQL to overload.
6. Cron Jobs or Background Processes
WordPress cron and 3rd-party cron jobs can spam database with too many operations—especially WooCommerce and subscription plugins.
How to Fix “MySQL Too Many Connections” (Step-by-Step)
These steps are listed from easiest to advanced. Follow them in order for the best results.
1. Increase MySQL max_connections (Fixes 90% of Cases)
If your site is actually getting high traffic or growing, the simplest fix is increasing the connection limit.
Open your MySQL configuration file:
For MySQL:
For MariaDB:
Add or modify:
If your server is large (8–16GB RAM), go higher:
Then restart MySQL:
Or:
Before increasing too much:
Make sure you have enough RAM
MySQL consumes memory per open connection
Usually safe values: 500–1500
2. Disable or Replace Heavy Plugins
Check your plugins immediately. The most common offenders include:
-
Broken cache plugins
-
Page builder add-ons
-
WooCommerce add-ons
-
Security plugins logging every request
-
Email logs
-
Custom plugins written poorly
Run this query to find slow queries:
or enable slow query logging:
Then check:
Remove or replace the plugins causing repeated heavy queries.
3. Enable Object Caching (Very Important)
Object caching prevents WordPress from repeatedly querying MySQL.
If you have Redis or Memcached support:
Install Redis plugin:
Plugin: Redis Object Cache
Then enable it.
Add to wp-config.php:
Once Redis is enabled, database queries reduce by 40–70%.
A MUST for WooCommerce!
4. Optimize Your Database (Reduces Load)
Install one of these:
-
WP-Optimize
-
Advanced Database Cleaner
Then:
Delete post revisions
Delete expired transients
Optimize tables
Clean WooCommerce sessions
Clear cron logs
Or manually via SQL:
This reduces query time and connections.
5. Fix wp_options Autoload Bloat
One of the biggest hidden killers of MySQL connections is a bloated wp_options table.
Run this query:
If you see huge rows (over 1MB), those plugins must be fixed/removed.
6. Limit Bad Bots and Spam Traffic
Install:
-
Cloudflare Free
OR -
Wordfence (Rate limiting ON)
In Cloudflare, enable:
Bot Fight Mode
Rate Limiting
Security Level: Medium
This alone reduces database hits massively.
7. Increase PHP-FPM Process Limits (If Using FPM)
If PHP cannot process requests, they queue up and overwhelm MySQL.
Edit:
Set:
Restart FPM:
Adjust based on RAM.
8. Disable WP Cron (Huge Fix for Busy Sites)
WordPress cron fires on every visit → too many database queries.
Disable it:
Add system cron instead:
9. Upgrade Hosting Environment
If you’re on:
-
Cheap shared hosting
-
Weak VPS
-
1GB RAM server
…it will never handle high MySQL loads.
Move to:
-
Cloudways
-
RunCloud
-
GridPane
-
Hostinger Cloud
-
Kinsta
-
WPX
Choose a server with at least 4GB RAM.
10. Restart MySQL (Temporary Fix)
If site is down urgently, restarting MySQL clears stuck connections:
DO NOT rely on this as a permanent fix.
11. Optimize MySQL my.cnf Settings (Pro-Level Fix)
Add to:
Recommended settings:
Restart MySQL after saving.
This improves performance and reduces connection overload.
12. Check for Long-Running Processes
Run:
Look for:
-
Sleep processes
-
Locked tables
-
Queries stuck for 20+ seconds
Kill them:
Prevent “Too Many Connections” from Ever Happening Again
Follow these preventive steps:
Enable caching (Redis or Memcached)
Use Cloudflare
Optimize database monthly
Remove heavy plugins
Keep WordPress updated
Use proper hosting
Disable WP Cron
Monitor slow queries
You’ll never see this error again.
FAQs
1. What is the default MySQL max_connections?
Default is 151. On shared hosting, it may be lower (50–100).
2. What is a safe value for max_connections?
For most WordPress sites:
-
Shared hosting → 100–200
-
VPS 4GB RAM → 300–600
-
Large WooCommerce → 800–1500
3. Does increasing max_connections harm the server?
Only if your RAM is low. Otherwise, it’s completely safe.
4. How do I check current MySQL connections?
Run:
5. Can too many plugins cause this error?
Yes. Heavy or broken plugins frequently cause slow queries and connection overload.
6. Does WooCommerce increase database load?
Yes. WooCommerce is database-heavy and requires caching + optimized hosting.
7. Can bots cause MySQL Too Many Connections?
Absolutely. Bots can spam requests and crash MySQL, especially without Cloudflare.