if you meet one Error establishing a database connection notification in your browser window, your website cannot connect to the WordPress database. Failure to establish a database connection is a serious error that prevents visitors from accessing your website. In this article, we will show you how to fix the error when establishing a database connection in WordPress with several different methods:
What is Database Connection Establishment Error?
All information about your WordPress site such as posts, pages, plugin settings, user information is kept in the database. WordPress connects to this database every time someone visits your website.
The database in question stores media files (images and videos) and index.php, wp-login.php etc. It doesn’t store plugins/theme core files like
When someone visits your web page, PHP runs the relevant code on the page and retrieves information from the database and displays it to the site visitor in the browser..
To successfully establish the connection, you need the following information:
This information is located in the WordPress configuration file wp-config.php. If one of these parameters is not correct, WordPress will not be able to connect to the database.
In this case, the browser window Error establishing a database connection notification.
Because of this error, you cannot access the front end of your site and the WordPress admin panel.
Before you start troubleshooting, create a full backup of your WordPress site, as some of these steps will require editing database-related information. It is recommended back up your site regularly, especially if it is under frequent maintenance.
One of the most common causes of the error is incorrect access information so this is where your troubleshooting should begin. This issue is known to occur when migrating WordPress site from one host to another..
The information you need to access the database is contained in the WordPress configuration file. wp-config.php. You will find it in the root folder of your WordPress website. This file contains four lines of code (with database name, username, password, and database host) that must be correct to establish a successful database connection.
How to find database name, username and password?
You can easily find this information in your cPanel. Assuming your server is using cPanel, it should give you a direct link to access somewhere in your welcome emails..
However, if you can’t find this link, here is a tip to help you access your site’s cPanel dashboard anytime:
Therefore, you should be able to access cPanel by going to http://www.yoursite.com:2082 or https://www.yoursite.com:2083.
After finding your cPanel address, login to your hosting account and click on MySQL databases in the option Databases section.
When you access the MySQL databases section, you will see a single database for your site or a list of databases if your server hosts more than one site. Click on your site’s database to open it.
Then, if you want to find information about or make changes to a user account, find the column named. Privileged Users and choose the appropriate username. when you click on Manage User Privileges you will be able to edit and enable/disable user’s database privileges appropriate.
After checking the access information, you can also password change option. Find your site’s database in the MySQL list and click on change password.
This is a good solution if you are not sure which password you have chosen or if you want to reset it. Moreover create a new user for your database.
When you create a new user, simply add it to your database using the option below.
The database’s name and compatibility with your website can be verified using: phpMyAdmin option from cPanel.
When you click on this option, you will see the name of your database below. info_schema database used by your host. Click on your database name for see all the tables and data it stores.
To verify that the database is compatible with your website wp_options table. In the siteurl field, check the value entered for the URL address. If all goes well, your database is compatible with the website.
After verifying the information about the database name, username and password, you can change this information if necessary by modifying your wp-config.php file (required if you have created a new user).
After that, refresh your site to check if the error is gone.
Check database host information
If the database name, username and password are correct and the error still persists, verify if the information about the database host is entered correctly.
Many WordPress hosting companies use it localhost as the host for the database. However, some hosting providers use separate servers for their host databases. In this case, Contact your WordPress hosting provider to check information about your database host.
You can also refer to a list. POSSIBLE DB_HOST VALUES provided by WordPress. It contains parameters used by some popular WordPress hosting providers so that you can find the information you are looking for there.
In some cases, a damaged database may be the cause of the connection failure. This is a rare condition. it usually happens when you add a large number of tables to the database in the process of adding and removing plugins and themes.
After logging into your admin panel, you will see error notifications stating that your database is damaged. One or more database tables are unavailable. or The database may need to be repaired.
If this happens, it’s important to know that WordPress has a mod that you can launch to eliminate this error.
Access the wp-config.php file and code below ‘That’s it, stop editing! Happy blogs’
define('WP_ALLOW_REPAIR', true);
To see the settings for fixing the database, add the following link to your browser.
http://www.yourwebsite.com/wp-admin/maint/repair.php
Replace yourwebsite.com with your website URL.
You do not need to be logged in to the admin panel to access this page. When it opens, simply click the button to fix the database. This will start the process, which may take some time. When you fix the database, remove the code you added earlier. wp-config.php file.
If your database access information is correct and you still cannot establish a database connection, inspect database server (MySQL server).
Large traffic on the server is one of the possible causes of a database server crash. Many hosting providers have traffic restrictions on their servers. This means it is more likely your server cannot handle huge traffic especially if you have shared hosting.. Also, if your database server is overloaded, your website speed will drop and some visitors may even receive an error message when they try to access it.
One way to solve this is to use caching plugins. They can help reduce database interactions on your website. A caching plugin creates a lighter HTML version of your page that it serves to visitors. This way the server doesn’t have to execute PHP code and MySQL database queries every time a new page is visited.
As an alternaive, contact your hosting provider and ask them to check if your MySQL server is working properly.
If you have multiple sites on the server, check them all out. To see if the MySQL server is running at low speed. Once the hosting provider has verified that your database server is working properly, do a quick test with your live site to see if the error is still there.
Final Tips
There is no way to completely avoid the error when establishing a database connection in WordPress. However, there are ways to minimize the risk; make sure your database access credentials are valid, buy high-quality hosting, and make regular website backups.
Choose hosting providers whose platforms are optimized for WordPress. That way, you can always count on their support. At the same time, you will avoid minor glitches and bugs caused by incompatibilities with WordPress.
Regular site backups should be part of your site administration’s daily routine. You can do this using backup plugins that allow you to automate the process, or you can manually backup your WordPress website. That way, if your site crashes, you always have a ready-to-use copy that lets you revert to your last working settings before you start troubleshooting.
Support our work ❤️
If you enjoyed this article, consider leaving a tip to help us keep publishing great content.


























