If you are even slightly familiar with WordPress site then you must have seen or faced Error Establishing a Database Connection erorr issue. This error happens when WordPress is unable to connect to the database where all your website content is stored. In this guide, we’ll explain the common reasons behind this problem and show you simple, step-by-step ways to fix it. So please follow and check our every steps with carefully.

This error will be displayed if the debug mode is set to false in the config.php file if it’s set to true, the actual error will also be shown.
What is Error Establishing a Database Connection
Error Establishing a Database Connection is one of the most common WordPress problems, which means it will be displayed if your WordPress site is struggling to connect to your site database. The reason why the database is a big deal is because it contains all the information for you WordPress website, whether it is posts, pages, settings or even user information.
All the important information of your WordPress site like posts, pages, plugin settings, user details, and login data are stored in the MySQL database. The only things not saved in the database are your media files, such as images, and your website files like themes, plugins, and core WordPress files (for example, index.php or wp-login.php file).
For example when a visitor accesses your WordPress webiste then WordPress executes PHP in generating code to retrieve information from your database and display itn on their browser to your site’s viewers.
In such case the process does not work as expected, WordPress will display the “Error Establishing a Database Connection” error message. Due to the fact that the system cannot obtain any information from the database due to wrong credential, the error results in a blank page. This will not only affect the front end of your website but will also prevent you from accessing the WordPress administration interface.
Why Does This Error Occur?
This error usually occurs when the database name, username, or password is incorrectly entered in the config.php file, or it could be due to server issues, corrupted database tables, or problems with your hosting.
- Incorrect Database Credentials: The database name, username, password, or host in your wp-config.php file is incorrect.
- Corrupted Database: The database may have become corrupted due to a plugin, theme, or server issue.
- Database Server Issues: The database server may be down, overloaded, or misconfigured.
- Corrupted WordPress Files: Core WordPress files or plugins may be corrupted.
- Hosting Problems: Your hosting provider may be experiencing server issues.
Step-by-Step Solutions to Fix the Error
1. Check Your Database Credentials
The wp-config.php file contains your database connection details. If these are incorrect, WordPress cannot connect to the database.
- Access your WordPress files via cPanel or File Manager plugin. Here is showing example of cPanel

- Click on File Manager where you will get the public_html folder but also check your sites on the public_html page as many times sites are added outside of public_html as we can decide when adding the domain and look the wp-config.php file in the root directory of your WordPress installation.

- Open wp-config.php file and check the following lines:

// ** MySQL settings - You can get this info from your web host ** //
/** Please change these details according your databse details */
define('DB_NAME', 'wperrorfixer_database_name');
/** MySQL database username */
define('DB_USER', 'wperrorfixer_username');
/** MySQL database password */
define('DB_PASSWORD', 'wperrorfixer_password');
/** MySQL hostname */
define('DB_HOST', 'localhost');
- Verify these details match the ones provided by your hosting provider. You can usually find them in your hosting control panel cPanel.
- If any information is incorrect, update it and save the file.
- Refresh your website to check if the error is resolved.
Tip: If you’re unsure about the credentials, check your hosting account’s database management section.

2. Repair a Corrupted Database
A corrupted database can cause connection issues. WordPress has a built-in repair tool to fix this.
Steps:
- Open your wp-config.php file.
- Add the following line at the bottom of the file: define(‘WP_ALLOW_REPAIR’, true);
- Save the file and visit your site like this https://wperrorfixer.com/wp-admin/maint/repair.php in your browser.
- Click the “Repair Database” or “Repair and Optimize Database” button.
- Once the repair is complete, remove the WP_ALLOW_REPAIR line from wp-config.php for security reasons.
- Check your website to see if the error is resolved.
Note: If the repair tool doesn’t work, you may need to use phpMyAdmin (available in most hosting control panels) to manually repair tables. Select the database, check all tables, and choose “Repair table” from the dropdown.
3. Check the Database Server Status
If the credentials are correct and the database isn’t corrupted, the database server itself might be down or experiencing issues.
Steps:
- Contact your hosting provider to confirm if the database server (e.g., MySQL or MariaDB) is running.
- If you have access to your hosting control panel, check the database server status.
- If the server is down, ask your hosting provider to restart it or resolve any server-side issues.
Tip: If you’re on shared hosting, server overloads can cause temporary issues. Consider upgrading to a better hosting plan or switching to a more reliable provider.
4. Reupload Core WordPress Files
Corrupted WordPress core files can sometimes cause database connection issues.
Steps:
- Download the latest version of WordPress from wordpress.org.
- Extract the downloaded zip file.
-

- Since i am using cPanel, if you also use cPanel then you should login to cPanel and click on public_html and select your domain if you have added multiple domains.
- Open that domain by clicking on it where you will find all the files folders of WordPress. Select all the files folders and then delete all the files folders except wp-contents folder, wp-config.php, robots.txt, htaccess and verification files if there are any.

- Upload the WordPress zip file using the upload option in cPanel. After uploading, click on extract and WordPress where you will find all the core files folder of WordPress and select all of them except wp-contents and move them to your domain.
- Be careful not to overwrite the wp-content folder, as it contains your themes, plugins, and uploads.
- Refresh your website to check if the issue is resolved.
5. Check for Plugin or Theme Conflicts
A faulty plugin or theme might interfere with the database connection.
Steps:
- Access your WordPress files via cPanel or your hosting file manager.
- Navigate to the wp-content/plugins folder and rename it to something like plugins_backup to deactivate all plugins.
- Check if your website loads. If it does, the issue is with a plugin.
- Rename the plugins_backup folder back to plugins and rename each plugin folder one by one (e.g., plugin_name_backup) to identify the problematic plugin.
- Similarly, switch to a default theme (e.g., Twenty Twenty-Five) by renaming the wp-content/themes/your-theme folder and checking if the site loads.
Tip: Once you identify the faulty plugin or theme, update or replace it with an alternative.
6. Contact Your Hosting Provider
If none of the above steps resolve the issue, your hosting provider may be experiencing deeper server issues.
Steps:
- Contact your hosting provider’s support team and provide details about the error and the steps you’ve tried.
- Ask them to check for server-side issues, such as database server downtime, resource limits, or misconfigurations.
- If the issue persists, consider switching to a more reliable hosting provider.
Prevent Future Database Connection Errors
To avoid this error in the future:
- Regular Backups: Use plugins like UpdraftPlus or BackupBuddy to regularly back up your database and files.
- Keep WordPress Updated: Update WordPress core, themes, and plugins to their latest versions.
- Choose Reliable Hosting: Opt for a reputable hosting provider with good uptime and support.
- Monitor Database Health: Periodically check your database for errors using tools like phpMyAdmin or WordPress database plugins.
Conclusion
The Error Establishing a Database Connection in WordPress can feel overwhelming, but it’s a common issue that can be fixed with the right approach. Start by checking your wp-config.php credentials, then test your database connection, and repair any corrupted tables. If the problem persists, review your server settings or replace corrupted WordPress files.
Always begin with the simplest fixes before moving on to advanced troubleshooting. And if you don’t have the technical expertise to resolve this error yourself, you can rely on Wperrorfixer to quickly fix the issue and get your WordPress site back online.








