Self-Publishing Channel about Learning and Technology

What is the Error Establishing a Database Connection Error & How to Address it?

It is not uncommon for WordPress websites to have the Error Establishing a Database Connection error. Most website owners take it to be a complicated error that needs the help of an expert. However, the issue is not as complex as it may appear on the screen.


 

What is the Error?

The Error Establishing a Database Connection error in WordPress means that the PHP code cannot connect to the MySQL database because of some reason. This prevents it come retrieving information required for creating a page. The error appears on a blank page, as the code is unable to get the required information to be presented on that page.

This guide introduces the reasons why this error occurs in WP and different methods for fixing it.
 

Reasons behind Error Establishing Database Connection

The database error in WordPress could be caused by a number of reasons. This includes the following:

  • Corrupt Database: The WP database can get corrupted due to several reasons. This can include installation of a plugin that has bugs or is incompatible with existing plugins or themes of the site.
  • Incorrect Login Details: The use of incorrect login username and password for logging into the admin panel can also cause this error. So make sure that you are using the correct login details. It is likely that the username/password may have been updated and you are still using the old one.
  • Server Down: The Error Establishing a Database Connection may also be caused due to the server being down temporarily.


 

Fixing the WordPress Error

Follow these methods to fix the Error Establishing a Database Connection error in WordPress:
 

1. Use WP_ALLOW_Repair

Your database needs to be repaired if you notice the following types of error:

  • The website is functioning normally and the error appears only when you try to access your wp-admin page.
  • When you try to access your WP site, you get an error message – “one or more database tables are unavailable….”

Both these messages mean that the database is corrupt and needs to be repaired.

WordPress offers a database repair option so that you can repair a corrupt database. Just like most other features of WP, you can use this option without advanced technical skills.

  • Connect to your WP site using FTP
  • Download the file, wp-config.php (the file is in the root folder of your WP installation)

  • Open this file using a text editor
  • Search for the code: if ( !defined(‘ABSPATH’) )
  • Add the following code after this code: WP_ALLOW_REPAIR
  • Save the file
  • Upload the wp-config.php file back to the server
  • Open http://yoursite.com/wp-admin/maint/repair.php
  • Click ‘repair database’ (a better option is to click on ‘repair and optimize database’
  • Delete the ‘WP_ALLOW_REPAIR’ code from the file and upload the file back again on the server

 

2. Changing Login Details

If the above-mentioned method doesn’t help fix the WP Error Establishing a Database Connection message, you should change the login details. The login settings are present in the wp-config.php file.

  • Open this file using the steps mentioned above
  • The login details are provided at the top of the file
  • Check the data against DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST and ensure that they are correct

Another method is to check the database using PHPMyAdmin.

  • Log into your PHPMyAdmin account
  • Locate your database and click on it (you can match name from the database name within wp-config.php file)
  • Locate the table with the name, wp_options
  • Click on ‘browse’
  • Check the URL, name, and other settings on the new page and match it with the details in the wp-config.php file

If the details are not matching, you should correct them in the wp-config.php file.

You can also check and ensure the username/password are correct using the following steps:
 

Creating .php file for testing username/password

  • Create a new .php file with any name (not already existing) and add it into the following code: <?php $test Connection = mysql_connect(‘localhost’, ‘root’, ‘password’); if (!$testConnection) { die(‘Error: ‘ . mysql_error()); } echo ‘Congratulations! The database connection works!’; mysql_close($testConnection); ?>
  • The code tests the connection
  • It will let you know if the connection is successful

If the connection is not successful you will have to create new login details. You will need the MySQL Databases tool for creating new username/password.

  • Click on MySQL Databases
  • Open MySQL Users menu
  • Click on ‘add new user’
  • Add the new login details in the new page
  • Note down the username/password
  • Click on ‘create user’
  • Click ‘add user to database’
  • Select the new username and WP database
  • Click on ‘add’

When the new username has been added to your database, make sure the wp-config.php is updated with the new credentials.

This should help you fix the Error Establishing a Database Connection error in WordPress if the issue was with the login details.

So if you are facing the Error Establishing a Database Connection in WordPress, make sure to follow the above-mentioned methods. The 000Webhost blog post provides an even more detailed guide on fixing the error. If the problem continues without getting resolved, you should contact your web host’s support team. If there is no other plausible cause, the issue may be at the server end. Make sure that the support team knows what steps you took to fix the problem.
 

Conclusion

The Error Establishing a Database Connection error can be a frustrating issue with your site. The above-mentioned methods have covered most of the underlying causes that result in this error. In most cases, these steps are enough to fix the error. And you will not need any advanced skills or knowledge to follow the steps. If you are still unable to resolve the error, it is recommended to check the 000Webhost blog post. It provides an in-depth coverage on the topic. And as a last resort, you could contact the web host customer support considering that the issue is from the server end.
 
 

Leave a Reply

Your email address will not be published. Required fields are marked *

68 − = 60