WordPress: Error connecting to database


Since moving my WordPress site to DigitalOcean, I started receiving "Error connecting to database" pretty regularly.

It seems to be MySQL going down for some reason. Restarting MySQL will sort it out.

service mysql restart

Never had it on my previous VPS.

Don't know why it would be Digital Ocean specific.

But anyway. One common issue seems to be xmlrpc attacks.


You can check in your logs for it:

grep xmlrpc /var/log/apache2/access.log

I don't use Jetpack, so more than happy to disable xmlrpc.

<files xmlrpc.php>
  order allow,deny
  deny from all

Once this is set up, any access attempts you see in your logs should now be 403s.

The error still seems to happen though periodically. It seems Apache makes MySQL fall over?

Quick and dirty cron job to restart MySQL regularly:

*/20 * * * * /usr/sbin/service mysql restart

A better one is a script to check if MySQL is down, and restart it if so.

There's also some tweaks you can make to Apache and MySQL conf.

This page last updated: 2021-07-24 Sat 12:02. Map. Recent changes. Source. Peer Production License. Webring: << random >>