WordPress is the powerhouse for web development and designing. If you navigate the browser today 1 in every 3 websites are developed on WordPress today. According to ResearchGate, the market share of WordPress is 55%.
Even though most businesses term WordPress a well-oiled machine. But, nothing can sully your mood if you come across an error establishing a database connection.
First, let us understand what is error establishing a database connection is?
WordPress uses MySQL. So, whenever a visitor visits the website, specific ‘PHP command’ fetches the information from the database. It is then displayed on the browser of your visitor.
Note:- MySQL is a data management system!!
Now when an error appears on your website, it will not communicate with the WordPress database. As a result, there won’t be any data to retrieve and the whole website goes down.
This error message does not appear at the front-end. But this scenario sustains as long your website’s cache is available
The database error will block access to your WordPress dashboard. Hence, it is prudent to find the culprit for this error and fix it.
Here in this post, we will talk about error establishing a database connection. Before wasting any time further, let’s dig in!
What are the main causes of error establishing a database connection in WordPress?
- Corruption in core files
The core files of WordPress define how your website functions and works. One of the main reasons is corrupted files, faulty plugins, issues in themes while transferring through an FTP client. So, if you make any incorrect modifications, the core files also get corrupted. It causes failure in the whole database.
- Incorrect login credentials for database
Always remember that the WordPress database employs different login details from the hosting panel. If you change the username as well as the password, the old information will be invalid. It will store the old data.
- Corrupted database
Issues such as incompatible themes and plugin failures can cause missing information & corrupted database tables. So, when any database details are corrupted or deleted, it will lead to an error.
- Database server error
There are times when errors happened from the web hosting end. An instant permission issue or traffic surge can make the database unresponsive. It usually arises in the shared hosting environment. In this case, different websites employ the same resources.
If you are seeing White Screen of Death, then please read this blog.
How can you fix an error establishing a database connection in WordPress?
There are six ways to fix an error establishing a database connection in WordPress. But before you do that ensure to create a backup of your website. Why? Well, if things go in the wrong way, you will always have a backup to restore the website.
Six ways to fix an error establishing a database connection in WordPress
- Ensure that your domain points to the hosting provider
If you switch to a new host provider, the files will move to a new host. If the domain is not pointed to the correct host it will cause database failure.
For this, check the nameservers for error establishing a database connection in WordPress. If the nameservers match then your domain is correctly pointed. Otherwise, you need to change the nameservers at the domain registrar.
First, you need to access the dashboard of hosting. Here, you can get the nameservers list.
You can even try an alternate option. For this, you can point to the domain name through A record. You will also hear it by the term DNS record. This will assist to assign the domain to the correct IP address.
- Point to remember
A record can only point to a static IP address. Replace it with a new web host for error establishing a database connection in WordPress. You can use an online DNS checker or computer console to do this.
- Check the credentials of database login
Still, facing trouble to open your site successfully. You must ensure to do the investigation of your login settings. Search for this in the wp-config file. There might be the case wherein your login credentials of the database might have stopped working. There might be two cases.
- It arises because you may have replaced the hosting company.
- Or else you have changed the important details regarding your database
It might not have been updated in the wp-config file manually.
For this, check the wp-config file for error establishing a database connection in WordPress. Search to find the details of the database login.
It might not have been updated in the wp-config file manually.
For this, check the wp-config file for error establishing a database connection in WordPress. Search to find the details of the database login
- It will display the following database as
- DB_NAME” for the Database name
- “DB_USER”, for Login username
- “DB_PASSWORD” for Login secret
- “DB_HOST” for Data set host
Ensure these details are right. Why? It is because WordPress will not be able to associate with the database for incorrect values.
You can actually look at the database outside WordPress. For this, you can utilize PHPMyAdmin. This is essentially a tool to edit and access the MySQL database. However, be cautious when you use this tool as it manages the database of your website.
- Database name
- Log in to the account of “PHPMyAdmin”. On your server, tap the database from the list of databases.
- Next click on the database name. Here, you will see plenty of table names in your database.
- Tap the button “Browse” for error establishing a database connection in WordPress.
- One will be guided to the general settings, URL, and name. Ensure it is similar to the wp-config file. If it is not the same, fix this in the wp-config file before continuing further.
You are sorted with the database name!!
- Username and password
Create a .php file for the existing user. You can use the credentials from the wp-config file.
To test, create a .php file and give a name to it so that you can remember it later. Next, add the code. You can get WooCommerce Support from a good team, they will effectively help you with codes.
This code permits you to test the connection. For this, go to the file URL of the browser. You can connect successfully or in the most pessimistic scenario. There are high chances of one more error appearing. It is an indication that your past credential for login is not correctly working.
To generate a new database user and password, you can use different tools. These are accessible in cPanel and are termed MySQL Databases. Under the section “MySQL Users”, tap the button “Add New User”.
So, whenever you choose a username and password, save it to the wp-config file. Tap “Create User” and hit the button “Add User to Database”. Pick a new WordPress database and username. Hit “Add”.
Here, you will be adding new users for error establishing a database connection in WordPress. Next, update the p-config file with the new password and username
- Fix the corrupted files
This is the last option that you can do to fix error establishing a database connection in WordPress.
Make sure to be careful about the main system files. Your minute mistake can wipe your entire website. Hence, make a backup of your data.
The next thing you require is a fresh file of WordPress. This will take the place of old corrupted files that is troubling you.
Now follow the following step to do the entire process:-
- From “WordPress.org”, you must install a fresh copy of WordPress.
- Unzip this file to your drive. Make sure to delete the “wp-config” file and “wp-content” folder.
- Delete the corrupted or infected files. Then onto your WordPress root folder, paste the rest files. You can employ “File Manager” or can opt for “FTP client”.
These steps will replace the error or corrupted files. You can quickly fix the error establishing a database connection in WordPress. Make sure to reload the page.
You are all set to rule the planet with your website!!
Wrapping It Up
The error establishing a database connection in WordPress is a frustrating situation. There can be numerous root causes that make it quite hard to resolve and identify.
Here, in this post, we have majorly covered all the main causes that cause errors. If you still cannot solve the issue, hire Just Another WP. You can get WordPress support, WordPress critical error support, etc., from us.