How to Fix Error Establishing a Database Connection Error in WordPress

My WordPress site was working fine until the last few hours. But now, it is showing the “Error Establishing a Database Connection” error. The image of the error is attached below
Error Establishing a Database Connection
Can anyone tell me how to fix this problem and make my site running again?

There are several reasons for the error establishing a database connection error. Below are some of them.

  • Your database server is running out of resources
  • The database connection with your wp-config.php file has some errors (for example a mistyped database name, or database user name, or database password)
  • Your database is corrupted (the chances are very small)

The first thing I would recommend you to do is immediately contacting your hosting provider and ask them for a solution. In most of the cases, they will resolve the issue within a matter of minutes.

If you can’t reach them for any reason, here are some of the tips you could follow.

  • Make sure that your server is not overwhelmed and running out of resources. You can do this by visiting your hosting account.
  • Check the wp-config.php in the WordPress installation directory and compared the database name, database username, and the database password. Make sure that they are entered correctly.
  • Repair your WordPress database either from the database manager in your cPanel or hosting account, or by adding define ( ‘WP_ALLOW_REPAIR’ , true); to the wp-config.php. If you use this code, when you try to access your website’s backend, a database repair screen will open up (I do not recommend this unless you tried every other method to fix the issue.

Hope you fix the problem. :slightly_smiling_face: