WordPress: Error establishing a database connection – what you can do

by Corinna

If you see “Error establishing a database connection” in WordPress, the initial shock is great. In most cases, you can fix the error very easily

How to fix “Error establishing a database connection” in WordPress

In most cases, this error occurs after the connection data of your database has changed. This can happen, for example, after moving your website to a new server.

  • First find out the connection data of your WordPress database. You can obtain these either from your database administrator or via the control panel of your hosting provider. In Plesk, for example, you will find an overview of your databases and the connection data for each individual database under the “Databases” menu item. You can also reset the password there. If you do not know how to do this, ask your hosting provider or look through their help pages.
  • Now you need FTP access to your server in order to edit the files on it. To do this, use a client such as FileZilla and connect to your server. Many hosting providers also provide you with a file manager via the control panel. In Plesk, for example, simply click on “Files” in the menu and navigate to the installation directory of your WordPress installation.
  • In the root directory of your WordPress installation (often named after your domain or httpdocs) you should find a file called wp-config.php. In it, you can easily adjust the settings for the database with a text editor and upload the updated version back to your server.
  • The following variables are responsible for the database connection: define( ‘DB_NAME’, ‘insert-here’ ); define( ‘DB_USER’, ‘insert-here’ ); define( ‘DB_PASSWORD’, ‘insert-here’ ); define( ‘DB_HOST’, ‘insert-here’ ). Change all the places “insert-here”. Take care not to remove the single quotation marks. Enter a port to the host server as a suffix separated by a colon, e.g. like this: 127.0.0.1:3307
  • The $table_prefix setting specifies whether the tables in your database have a specific prefix. If in doubt, you can read this out by accessing your databases. In your host’s control panel, you can usually log into an administration tool such as phpMyAdmin with a single click. In most cases, however, this setting should not be the error:
  • If you cannot resolve the error in this way, temporarily add the following lines to the config file for troubleshooting and call up your website. You should now see a more detailed description of the problem, which you can search for on the Internet if necessary: define(‘WP_DISABLE_FATAL_ERROR_HANDLER’, true ); define( ‘WP_DEBUG’, true );.

 

Related Articles

Leave a Comment