Its every website owners worst nightmare - their website all of a sudden going down or showing the above error.


Are you seeing the ‘Error establishing a database connection’ notice on your WordPress website?
It is a fatal error that makes your WordPress website inaccessible to the users.


This error occurs when WordPress is unable to make a connection to the database. A number of things can affect your WordPress database connection which makes it a bit difficult for beginners to troubleshoot.





What can cause this error?



This error is usually database related.

It can happen if you have missed or mistyped any of the following items:


  • Database Name
  • Database Username
  • Database Password
  • Database Host




To manage the database(s) on your account, when you sign in you will see the option for 'Databases' on the right hand side menu.






Here you can view/manage all databases - if you click the 'Show More' dropdown option you will then see the available actions.


A useful tool is the 'Check and Repair' - this will scan your database for any inconsistencies and try to repair these automatically. This could either be incorrect privileges or values in columns. 






By clicking on 'User Management' you will be able to view/manage all database users and change any details if required - if you make any changes here be sure to update this also in your 'wp-config.php' file.





9/10 times we recommend checking the 'wp-config.php' file in your website root directory (this will either be 'httpdocs' or 'httpsdocs', depending if you have SSL turned on/off).





wp-config.php



1
2
3
4
5
6
7
8
9
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME''database_name_here' );
/** MySQL database username */
define( 'DB_USER''username_here' );
/** MySQL database password */
define( 'DB_PASSWORD''password_here' );
/** MySQL hostname */
define( 'DB_HOST''localhost' );




For the below lines:


  • 'DB_NAME'
  • 'DB_USER'
  • 'DB_PASSWORD'



Make sure that the values match the database name, database user & database user password from the previous steps (if applicable).


For the 'DB_HOST' the value should be 'localhost:3306' - if the value is anything other than this be sure to update it and to save your changes.





Other Causes


99% of the time the issue is either with a database or the 'wp-config.php' file and can be quickly rectified.

However, there are other causes that can lead to this error.


There can be:



  • Outdated WordPress Version - we recommend checking here to see what the latest stable release is and updating your WordPress install if it is outdated.


  • Unsupported Plugins or Themes - depending on your WordPress & PHP version(s), some 3rd party plugins/themes may stop working if you upgrade your settings. We advise you to check the compatibility of installed plugins/themes and only update if you are sure this will not break your website.


  • PHP Version - If you are running WordPress on PHP < v7.4 we advise you to change this to 7.4 > as newer versions of WordPress, along with plugins & themes, may not be supported on older versions of PHP.
    We also advise to run WordPress on the latest version, or the last supported version if there are any issues, for security & performance purposes.