Recently, I started getting Error establishing a database connection on one of my WordPress sites. There could be many reasons for this error, but in this case, it was due to heavy bot traffic attempting to scrape content.

The problem was so critical that even my hosting provider gave up trying to solve the issue. Thankfully, I was using Cloudflare CDN for my sites. After multiple attempts to resolve the issue from the database side, as it was a database error, I didn't think it could be resolved by Cloudflare. I decided to try activating Under Attack Mode, and suddenly everything was sorted out.
However, as you can't keep Cloudflare's IUAM (I'm Under Attack Mode) active long-term for reasons mentioned in this article, Does Under Attack Mode Block Google Search, I had to find the actual problem. After some research, I found that heavy bot traffic was hitting my site using a specific query string. I created some Cloudflare rules to block it, and everything was resolved.
This experience taught me an important lesson: sometimes the solution to a technical problem isn't where you expect it to be. While I was focused on fixing the database issue directly, the real solution was at the traffic level through Cloudflare.
If you're facing similar "Error establishing a database connection" issues that seem unsolvable through traditional database troubleshooting, consider looking at your traffic patterns and implementing protective measures at the CDN or firewall level. A multi-layered approach to website security and performance can save you hours of frustration and potential downtime.
See also: How to Disable All WordPress Plugins from cPanel


