You’re trying to access your website, which was running smoothly the last time you visited, but instead of the homepage, you’re faced with the WordPress error message “Error Establishing a Database Connection“.
The database connection error can cause goosebumps to the best of us but guess what? This error is entirely manageable and is one of the common WordPress errors. And I will show you how to fix the ‘error establishing a database connection’ in 6 different ways.
So, don’t sweat and keep reading.
Contents show
What is a WordPress Database?
Before you troubleshoot the database error, you should know what the heck the word database means and why it is so important. Well, WordPress utilizes the MySQL database for storing all information related to your website. This includes information about your login credentials, users, plugins, posts, and pages.

The media files and other uploads are not stored in the database but are stored in the wp-content folder separately.
WordPress retrieves all the information it needs from the MySQL server constantly. If there is an error in your database, WordPress will not be able to communicate with the MySQL server and will throw up a database connection error that we will troubleshoot below.
1. Check your database credentials
The most common reason why the database connection error occurs is due to wrong credentials in the wp-config.php file.
This file is located in your root WordPress installation. You can use either an FTP program like FileZilla or a file manager in your hosting panel to access your WordPress directory.
Next, navigate to the directory where WordPress installed. If you can see the folders wp-content, wp-includes, and wp-admin, you are in the right place.
Now scroll down to the wp-config.php file. Before tinkering with this file, you should backup all its contents.
So, open the file and copy all the contents of the file. Now create a text file with some name like wp-config.txt on your computer and paste the copied contents. Save the text file.
You can now return to editing the wp-config.php file.
The wp-config.php file contains the details of your WordPress database. If there is any error here, it can throw up the database connection error.

There are 4 important things to verify here:
- Database name
Look for the line:
define('DB_Name', 'Name');
The ‘Name’ should match with your database name. To know your database name, you can either ask your hosting provider or you can access your MySQL database using your hosting panel.
Once you log in to the MySQL panel, you can see your database name on the left panel just below the information_schema.

Alternatively, you can click the Databases tab on the top to know your database name.
Ensure that the name matches the one in the wp-config file. If not, make the correction and save the file.
Related: WordPress Database Management and Optimization Guide
- Database username and password
The database username and password in wp-config.php should also tally with the actual username and password.
If you’re using cPanel then the database username will be listed under the Databases tab. If you’re using a custom panel like Dreamhost (which we are), then the database details like username and password will be listed under the Manage Database tab.
ad

In case of any doubt, just ask your hosting provider for the database username and password.
Now, ensure that the username and password match with those in the following two entries in the wp-config.php file.
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
If they match, there’s nothing to do here. But if they don’t you should update the entries with the correct username and password.
- Database hostname
Finally, check this line in the wp-config file:
define('DB_HOST', 'localhost');
This defines the MySQL (database) server location in the wp-config file. Most of the time, your database server will be the same as the one on which WordPress is installed. In this case, the hostname will correspond to ‘localhost’.
But if your database is located on a separate server, as in the case of Dreamhost, then the proper host location should be present like mysql.yoursite.com.
When in doubt, ask your hosting support for the correct database host entry.
2. Database connection error caused by plugins
In any type of WordPress error, a malfunctioning plugin or theme is the usual suspect.
To find out whether the error is caused by a plugin, log in to your web hosting panel and use the file manager to go to your WordPress directory. You can also use an FTP program like Filezilla for this if you don’t have access to a file manager.
In the WordPress directory, go to the wp-content folder. Within this, there is a ‘plugins’ folder. Rename this folder to any other name like plugins.hold or plugins-old.

This will deactivate all plugins on your website. Check your site; if the database connection error has disappeared, it means that one of the plugins was causing the error.
To identify the misconfigured plugin, log in to your website and go to the plugins dashboard. You will see an error message that ‘plugins have been disabled since the plugins folder does not exist’.
Don’t panic. Just restore the plugins folder to its original name i.e. ‘plugins’ in the wp-contents folder.
Next, head back to the plugins dashboard. You will see that all plugins are in a deactivated state. Now activate all plugins one by one.
If the database connection error recurs when you activate a plugin, means that the plugin was causing the error. You should deactivate the plugin to resolve the error.
However, if renaming the plugins folder did resolve the database connection error, you should follow the next step after restoring the name of the plugins folder in your WordPress installation.
3. Error connecting to database server
Sometimes, due to a sudden spike in website traffic, your database server is unable to handle the load, leading to a connection error. This situation is more likely to occur on shared hosting as compared to VPS or dedicated hosting.
In order to verify the connection between the database server and WordPress, you need to do the following.
- If you have another website hosted on the same server then simply visit that site. If it connects, it implies that the database connection is fine.
- If you have a single website, then first log in to phpMyAdmin and then connect to your database by selecting it. If the database tables show up, then the connection is OK.
If for any reason, the connection fails then you should your hosting support and ask them to resolve the error ASAP.
4. Error in the database
If there is some error in the database, it could also cause the database connection error. In this case, you will need to repair your database. Fortunately, this is quite easy to accomplish.
Again, open the wp-config.php file for editing as described in step 1.
Then, add the following line of code after this line: define('DB_COLLATE', '');
define('WP_ALLOW_REPAIR', true);
What this code does is allows you to access the database repair options on your site. This option can be accessed by visiting the following link:
https://yoursite.com/wp-admin/maint/repair.php
Here, you will see the following two options.

Click on the ‘Repair Database’ button to repair the database. Once you have done this, delete the code you added in the wp-config.php file.
Now check whether the ‘error connecting to WordPress database’ message has vanished. If it has, your problem is solved. Otherwise, move to the next solution.
Finding this solution required considerable effort and time. Consider rewarding me with a coffee!
5. Corrupted WordPress files
Sometimes, adding or deleting files can cause some core WordPress files to become corrupted. These files which are located in the wp-admin and wp-includes folders are vital for the smooth working of your website.
To rule out the possibility of corrupted files, you will need to replace the wp-admin and wp-includes folders in your WordPress installation.
Before, you proceed further I highly recommend that you take a full backup of your website using a free backup plugin like UpdraftPlus.
Now, you should download a fresh copy of WordPress from here.
Next, unzip the files to your computer. In the unzipped files, you will see three folders: wp-admin, wp-includes, and wp-content. Delete the wp-content folder since we don’t need to upload it.
Next, upload the wp-admin and wp-includes folder to your WordPress installation using an FTP program like FileZilla.
You can also use your File Manager to upload the folders. When the ‘overwrite files’ message pops up, allow overwriting the existing files in these folders.
Once all the files have been replaced, visit your website. Hopefully, you will no longer see the database connection error message.
6. When everything fails
I have described five solutions to the WordPress database connection error. Hopefully, one of them worked for you.
In the unlikely event that none of the above methods clicked, you should contact your hosting support forthwith.
After all, every minute of downtime will cost your readers and possible revenue loss.
Describe your problem in detail and any plugin or theme that you might have installed before the error occurred. Managed web hosting companies like Cloudways have dedicated WordPress support and should resolve such errors easily.
You can also check out our reliable WordPress troubleshooting service to get expert help with this nagging problem.
Did you manage to fix the database connection error? If yes, which solution worked for you? Please let us know in the comments below.
Download the WordPress SEO eBook
Go from WordPress SEO Zero to Hero in no time. Also receive2 Bonus PDFswith this free eBook.
Take Action Now!
Give it a try. You will thank yourself later.
FAQs
How do I fix error establishing a database connection in WordPress? ›
- Inspect the wp-config.php File of your WordPress website.
- Check if the Database User has the Correct Privileges.
- Repair the Database.
- Inspect the WordPress Site URL in the Database.
- Restore a Backup of the Site.
- Contact the Web Hosting Provider.
Check Your Database Login Credentials
The first thing to do is check to ensure your database login credentials are correct. This is by far the most common reason why the “error establishing a database connection” message occurs. Especially right after people migrate to a new hosting provider.
Getting started with WordPress error troubleshooting
You can start by clearing your cache. A cache helps your browsers load sites faster by storing data. Clearing it helps you get rid of outdated content, which may be enough to fix your issue. You should also consider updating your theme, plugins, and WordPress core.
- Update WordPress Site URL. Try updating the WordPress site URL using phpMyAdmin. ...
- Rebooting Web Server. ...
- Ask for help.
Click on the Hosting on the top menu and then cPanel on the submenu. Find the Files section and click on File Manager. You may get a popup asking you to select the directory you want to start in. Choose the Document Root for option and select the website you want to get the database information for.
How do I connect my database to my WordPress site? ›PhpMyAdmin also allows you to easily import your WordPress database. Simply launch phpMyAdmin and then select your WordPress database. Next, you need to click on the 'Import' link from the top menu. On the next screen, click on the Choose file button and then select your database backup file you downloaded earlier.
How do you troubleshoot database errors? ›- Make sure that the server has the appropriate capacity to handle the load and is not shared with other systems.
- Check and make sure that the DB statistics are up to date.
- Check memory allocation to make sure that there are no unnecessary disk reads.
Possibly the most common cause of the Error Establishing a Database Connection is simply that WordPress has incorrect login credentials for your database. This could be either the database name, username, or password. Remember, these login details are different from the ones you use to access your site.
What is a database connection error? ›This error means that your website files (on the webserver) are not able to connect to your database (on the database server). This article lists some common reasons this error could display on your site, including: Incorrect database credentials in your config file.
What is the most common WordPress error? ›There are 4 main types of errors on WordPress: HTTP, PHP, MySQL and JavaScript errors. These errors can be due to an incompatibility between plugins, a corrupted file, a server or memory problem, etc. Some of the famous errors include the 500 error, White Screen of Death and database connection error.
What is a common issue with WordPress? ›
The WordPress internal server error is often the most common WordPress issue and the most confusing too. This error message typically shows up when something is wrong, but the server doesn't know where the problem is.
How do I check for errors in WordPress? ›To review your error logs, navigate to your /wp-content/ folder in your File Manager. Locate the debug. log file. This file will contain all WordPress errors, warnings, and notices that were logged.
How do I clean up my WordPress database? ›- Reduce the number of saved revisions. By default, WordPress saves revisions of your posts and pages. ...
- Prevent spam comments. ...
- Regularly empty your WordPress trash. ...
- Delete unused plugins and themes. ...
- Disable pingbacks and trackbacks. ...
- Delete unused media files.
WordPress uses connection strings to know which database to connect to. When your site is not connected to your database, it displays the Error establishing a database connection notification. To resolve this error, update the connection strings on your WordPress site.
How do I reset my WordPress database? ›- Install and activate the WP Reset plugin. ...
- Go to Tools > WP Reset.
- Scroll down to the Site Reset section.
- Type “'reset” in the Confirmation field.
- Click the Reset Site button.
- A popup message will appear asking you to confirm that you want to reset your site.
- Log into your server with the SSH credentials. ...
- Navigate to the root directory of your site. ...
- Next, update the WordPress version using the command wp core update . ...
- You will also need to update the database, for which the command is wp core update-db .
- Create the Virtual Machine.
- Install the MySQL Database.
- Prepare the MySQL Database.
- Replace the Static Website.
- Connect the Website to the Database.
- Select the Records in the Database.
- Insert a Record into the Database.
- Update a Record in the Database.
WordPress uses a database management system called MySQL, which is open source software. This means you'll sometimes hear your site's database referred to as a “MySQL database.” MySQL is what enables the database to store information and provide you with access to it.
What is the most common database error? ›Redundancy. This is one of the most common database errors that developers struggle with, especially when they are forced to keep different versions of the same data updated.
How do you handle database failure? ›- The effects of database systems can be mitigated by keeping the computer hardware and software updated and practising the proper backup process.
- File corruption can be mitigated through use of the log files to restore the database. Some corrupt files can be repaired through DBMS software.
What are the common types of data errors? ›
Data can be affected by two types of error: sampling error and non-sampling error.
How do I fix WordPress connection is not secure? ›The red padlock can happen if your websites has mixed content issues. You could either make sure that both URL values (WordPress Address and Site Address) at Settings > General include the HTTPS (not just HTTP), or install a mixed content/SSL plugin to do this for you.
What causes connection error? ›Summary. If you run into the “ERR_CONNECTION_RESET” error, it means that your browser can't establish a connection to the remote server. In most cases, it's due to a misconfiguration in your internet settings or something else that's blocking the connection.
What are the top 3 things that slow a WordPress site down? ›- Website has hidden malware. ...
- Poor web host. ...
- Running too many plugins. ...
- Using poor-quality plugins and themes. ...
- Not updating WordPress core, plugins, and themes. ...
- Unnecessary JavaScript or long CSS. ...
- Not optimizing images. ...
- Not using caching plugins.
What's the most commonly-hacked CMS platform? WordPress was the most commonly-hacked CMS (content management system) in 2021, according to Sucuri's annual hacked website report. Over 95.6% of infections detected by Sucuri were on websites running WordPress.
How do I fix redirect problems in WordPress? ›- Check your URL settings.
- Clear your browser's cookies.
- Upgrade to a dedicated IP.
- Restore your . htaccess file.
- Disable your plugins.
How to Detect and Correct Errors? To detect and correct the errors, additional bits are added to the data bits at the time of transmission. The additional bits are called parity bits. They allow detection or correction of the errors.
What is error log in WordPress? ›Your WordPress error log is a troubleshooting tool that can help you identify the plugins, themes, or code that are causing problems. You can then go ahead and find a fix for those WordPress errors.
Where is config file in WordPress? ›One of the most important files in your WordPress installation is the wp-config. php file. This file is located in the root of your WordPress file directory and contains your website's base configuration details, such as database connection information.
How do I restore my WordPress site without a database? ›- Search for your website or page on Google's or Bing's results page. ...
- Click on the arrow. ...
- Since we need a cached copy of your website, click on Cache option.
- Restore your website, pages or content, or whatever you need from this cached copy.
How to check database connection error in php? ›
Try this: <? php $servername = "localhost"; $database = "database"; $username = "user"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password, $database); // Check connection if ($conn->connect_error) { die("Connection failed: " .
How do I restore a SQL database in WordPress? ›- Log in to your cPanel account and under the “Files” section click on “Backup.” cPanel backup.
- Scroll down to “Restore a MySQL database backup.” Click on “Choose File” and select your *. sql file backup/export. Then click on “Upload.” cPanel restore MySQL database backup.
In order to manually optimize your WordPress site, you will first have to access PHPMyAdmin via your hosting provider. You will have to log in to cPanel, then open the PHPMyAdmin tool, and navigate to Databases. Then select the database you would like to optimize. Then select Check All to optimize all tables.
What does it mean when it says error establishing a database connection? ›This error means that your website files (on the webserver) are not able to connect to your database (on the database server). This article lists some common reasons this error could display on your site, including: Incorrect database credentials in your config file. The hostname isn't working.
How do I fill the database connection details in WordPress? ›- Step 1 - Open File Manager. Log into the one.com control panel. ...
- Step 2 - Open wp-config. php. ...
- Step 3 - Locate the login details. Usually, you can find the login details around line 20 in the wp-config file. ...
- Step 4 - Update details.
- Check If the Website Is Working. ...
- Disconnect from VPN. ...
- Reboot Your Network Device. ...
- Clear the Browser Cache. ...
- Deactivate Antivirus and Firewall. ...
- Disable Proxy Server Access. ...
- Reset TCP/IP Settings.
Incorrect data inputs are typically the most common error that may occur in data entry.
How do I manually update my WordPress database? ›- Navigate to the root directory of your WordPress site. ...
- Next, check for WordPress core updates. ...
- Update WP version by typing in wp core update . ...
- In case you need to update the database as well, you can run the following command: wp core update-db .
- And that's it!
Here are some reasons the Can't connect to local MySQL server error might occur: mysqld is not running on the local host. Check your operating system's process list to ensure the mysqld process is present. You're running a MySQL server on Windows with many TCP/IP connections to it.