WordPress sudden "database connection" error
About 2 weeks ago I fired up a Linode with the WordPress package from the marketplace and migrated one of my ecommerce sites over.
Everything worked fine, but later that day the website suddenly displayed the error Error establishing a database connection.
I rebooted the Linode and then it worked perfectly again.
Today this suddenly happened again, and once again I had to reboot the Linode for the site to come back up. Luckily I caught this quickly, I could have lost a lot of sales if I hadn't.
I have tried looking at both the Apache error log and the MariaDB error log, but both of those logs only show events from the point of the restart and onwards, not what happened before.
The database credentials in wp-config are correct (obviously).
I have tried running WordPress's database repair, but everything comes back OK there so there's nothing to repair.
So my question is how can I find out what happened, and how can I prevent it from happening again?
5 Replies
My guess is that on day one you were not hitting the new site but were still going to the old site because the new DNS nameservers had not propagated… or your DNS records at the registry (or nameserver) was wrong, etc.
Recheck the wp-config file as well as your ability to 'hit' the MySQL server on your linode via the command line for MySQL.
I've never used the one-click install so you might check the docs for that to make sure that all the config settings were made correctly.
Perhaps spin up a new Linode and this time do it the 'hard' way but installing Apache, PHP, and MySQL via the Linode documentation. I know that if you follow the guide everything will work (at least it does for me on Ubuntu 20.x)
One last thing… install phpMyAdmin (there is a guide on this) and see if you can hit the MySQL server with that.
I can access mysql fine through both the cli and phpMyAdmin.
Would really like to not have to start over again.
Config file is correct.
As @acanton77 has said. Especially if you’ve moved from another service provider to Linode.
Add this to your wp-config file:
define('WP_ALLOW_REPAIR', true);
Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php
Maybe that will help.
I would also disable each plugin via FTP. Just rename each one, one at at time and try to bring up the site. Start with disabling Woo.
Since you did a one-click install, who knows what junk it loaded.
Why not create a new folder in your domain like /wp2 and install WordPress manually. Use the default theme and use the same wp-config setting as on the broken site. (First, do a sql 'dump' of the DB via phpMyAdmin.)
I think your DB is OK, but that the WP you installed has some junk-code in it (perhaps) in functions.php in wp-content/themes/your-theme.
Your experience is why I never use one-click installs. :-(