Skip to Content

Fix “Error establishing database connection” in WordPress

Here’s how to fix the error establishing a database connection in WordPress.

1. WP-Config.php is probably the single most important file in entire WordPress installation. First, check all the wp-config.php file is correct and same without any changed.

define(‘DB_NAME’, ‘your-database-name’);
define(‘DB_USER’, ‘your-database-username’);
define(‘DB_PASSWORD’, ‘your-database-password’);
define(‘DB_HOST’, ‘your-localhost’);

2. Next, check login page whether get errors for the same “Error Establishing Database Connection”. It may be getting a ton of traffic especially if you are using a shared server. Immediately contact hosting provider.

3. If WordPress site shown “One or more database tables are unavailable. The database may need to be repaired” then you will need to repair your database.
You can do this by adding the following line in your wp-config.php file:

define(‘WP_ALLOW_REPAIR’, true)

4. Once you have done that, you can see the settings by visiting this page:

5. Next, the screen will appear with two repair options. Just click Repair Database.
The WordPress site will recover once completed repair.

6. Go to wp-config.php file and remove “define(‘WP_ALLOW_REPAIR’, true)”, and then Save the file.

Alex Lim is a certified IT Technical Support Architect with over 15 years of experience in designing, implementing, and troubleshooting complex IT systems and networks. He has worked for leading IT companies, such as Microsoft, IBM, and Cisco, providing technical support and solutions to clients across various industries and sectors. Alex has a bachelor’s degree in computer science from the National University of Singapore and a master’s degree in information security from the Massachusetts Institute of Technology. He is also the author of several best-selling books on IT technical support, such as The IT Technical Support Handbook and Troubleshooting IT Systems and Networks. Alex lives in Bandar, Johore, Malaysia with his wife and two chilrdren. You can reach him at [email protected] or follow him on Website | Twitter | Facebook

    Ads Blocker Image Powered by Code Help Pro

    Your Support Matters...

    We run an independent site that is committed to delivering valuable content, but it comes with its challenges. Many of our readers use ad blockers, causing our advertising revenue to decline. Unlike some websites, we have not implemented paywalls to restrict access. Your support can make a significant difference. If you find this website useful and choose to support us, it would greatly secure our future. We appreciate your help. If you are currently using an ad blocker, please consider disabling it for our site. Thank you for your understanding and support.