Table of Contents
In this article we will discuss about how to Fix: ‘Error Establishing a Database Connection’ issue in WordPress. You wake up one morning, make some coffee, and go to your workstation. You are shocked to see a blank white page with the message “Error Establishing a Database Connection.” You can’t get to the website no matter how many times you refresh. Every minute that your website is down, you lose the chance to get leads, convert them into customers, and make sales. Finding out that your website is down is one of the most frustrating things that can happen, especially if you depend on it for business.
The Mistake Getting a “Establishing a Database Connection” message is a serious problem that stops anyone from getting to your site. Fixing it should be your top priority. But if you don’t know how WordPress works, it can be hard to figure out what’s going on. The situation is serious, but don’t get too worked up and don’t panic! It’s one of many common WordPress errors that can be fixed. Keep reading this guide to learn more about how to fix the error that occurs when WordPress tries to connect to a database and how to Fix ‘Error Establishing a Database Connection’ issue in WordPress in a practical way.
Check your database host information
Fix: ‘Error Establishing a Database Connection’ issue in WordPress: Your MySQL hostname tells where your database is stored. Use the correct MySQL hostname if you want to connect to your database. Most companies that host WordPress use localhost, but some host their databases on different servers. This is especially true for hosts that take care of WordPress.
- Verify the database name, username, and password for your database are correct.
- Check if you are using the correct database location. To do this, contact your hosting company.
- Alternatively, you can use the phpMyAdmin tool to retrieve this information manually.
- If your provider offers cPanel, log into your cPanel dashboard.
- Look for the phpMyAdmin option within cPanel.
- Inside phpMyAdmin, locate the Database Server block. This will provide information about your server setup, including its location.
- Check the server location. For example, if it shows “LocalHost via UNIX socket,” your server is located at localhost.
- Connect to your site using FileZilla and open the wp-config.php file.
- In the wp-config.php file, find the section that defines the MySQL hostname:
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
- Verify if the hostname in the wp-config.php file matches the server location obtained from phpMyAdmin.
- If the hostname is incorrect, download the wp-config.php file to your local computer.
- Open the file in a compatible text editor and update the hostname information.
- Save the changes and reupload the edited wp-config.php file to your server.
- After uploading the file, WordPress should be able to connect to your server at the correct location.
Restore default WordPress files
There is a chance that the core files of WordPress will get messed up. Hackers may sometimes try to get into your site by changing the WordPress code. Or you could accidentally change one of the core files. There’s even a chance that a plugin could change the WordPress code without you knowing. If you want to know more information about this visit official WordPress support site.
- Restore your database connection by reinstalling a fresh version of WordPress.
- Download a clean copy of WordPress core.
- Unpack the archive and delete the wp-content folder.
- Back up your site to avoid losing any valuable information.
- Drag all of the fresh WordPress core files into your FTP client.
- Opt to override all of your previous files when prompted.
- Attempt to access your site to see if the error is resolved.
- Explore your site to ensure everything is functioning properly.
- Customize the fresh install if necessary to restore any site modifications or settings.
Check whether your database server is offline
- Occasionally, your database server may go down. In particular, this might occur if your site experiences a period of heavy traffic.
- You’re also at a greater risk of downtime if you’re using shared hosting or opted for budget-friendly hosting that offers limited resources. If your server is offline, WordPress will be unable to connect to your database and you’ll encounter an error.
- If you run multiple sites on the same server, it’s worth visiting all of these sites in your web browser. If they all display the same database error message, then you’ll know that this problem isn’t tied to a specific website. In this scenario, it’s likely that your database server is offline.
- Assuming that you’re running multiple sites on the same hosting account, you can also attempt to connect to your database via phpMyAdmin. If you encounter errors, or strange behavior inside this tool, then an unresponsive server may be to blame.
- If you suspect your database server is offline, then it’s a good idea to contact your hosting provider. Your web host may be able to give you a timeframe for when they expect to resolve this problem. They may even be completely unaware that your database is offline.
- If you have a dedicated server, local server, or Virtual Private Server (VPS), you can try rebooting your server manually. This process will vary depending on your setup and hosting provider, so you may need to check your web host’s documentation for more information. Alternatively, if you’re unsure how to restart your server, you can always contact your provider for assistance.
Check Your Database Credentials
This is what causes the error establishing database connection error most of the time. Incorrect database credentials don’t change on their own, but this could be the issue if someone has been making changes to the files, hosting, etc. The information is kept in a system called MySQL, which is a database management system. A server holds this database. WordPress needs the following information to get to the database on this server:
- Database name
- Username
- Password
- Database server
These are the log-in details for the database. The wp-config.php file holds all of this information. If any of this information in the file is wrong, WordPress can’t make a connection, and you get the connection error.
Check if your themes or plugins are corrupted
- WordPress’ huge community of themes and plugins are one of the platform’s greatest strengths.
- Sadly, adding third-party code to your website can result in conflicts, errors, and other strange behavior.
- There’s also a chance that this code may become corrupted. In particular, if you’ve recently added some new software, run any updates, or manually edited your site’s code, then a theme or plugin may be causing the database error.
- Fortunately, there’s an easy way to deactivate all of your themes and plugins. You can then test whether this resolves your database error.
- Using an FTP client like FileZilla, navigate to your wp-content folder. You can then control-click on the plugins directory and opt to rename it. You can use any title, as long as it’s not plugins. This will deactivate every plugin across your website. If this resolves the error, then you’ll know that third-party software is to blame. You can now rename this folder back to plugins in order to reactivate all of your plugins.
- In order to pinpoint the culprit, open this folder and rename each plugin in turn. As soon as the database error disappears, you’ll have successfully identified the plugin that’s causing so many problems.
- If deactivating every plugin doesn’t resolve the error, you can repeat this process with your themes directory. If neither of these tricks resolve the issue, then you’ll know that your third-party software isn’t contributing to your database issue.
What does WordPress’ “Error Establishing a Database Connection” mean?
When a website can’t connect to the WordPress database, the “error establishing a database connection” message appears and the page won’t load. Most of the time, this problem is caused by wrong login information or a broken database. When WordPress can’t connect to the database, the “Error Establishing a Database Connection” message shows up. WordPress was first written in PHP, and its database system was MySQL. When someone visits your site, certain PHP commands will ask the database for information about your site, which will then be shown on the browser of the visitor.
Since there is no data to get from the database and show on the browser, the “Error establishing a database connection” message from WordPress will appear on a blank page. As long as your website’s cache is up and running, this error message won’t show up on the front end. But because of this WordPress database connection error, you can’t get into the WordPress dashboard. With that in mind, it’s important to find out what’s causing the error and fix it. Keep reading to learn about the different things that could cause this database connection in WordPress error.