Let’s create your online succes together.
Unlocking the potential of your WordPress presence with tailored solutions that blend innovation, aesthetics, and functionality.
Let's Begin

How to Fix Error Establishing a Database Connection

A WordPress database connection error can disrupt your website's functionality and traffic flow. It's usually caused by incorrect user information or database corruption due to incompatible plugins or server issues.
WordPress Fixes
Umut Katırcı Developer

One of the most common errors caused by websites installed with WordPress is the error of establishing a database connection, which will not allow your users to visit your website and will negatively affect the traffic flow on your website until the problem is resolved. Unfortunately, it will reduce your interactions. When you receive the database connection error message, you will not find any tips on solving the error on the same page. So you may think that the solution is difficult, or even impossible. But the WordPress database connection error is an error that is not difficult to solve. We will show you the solutions below.

What is a WordPress Database Connection Error? What Are the Reasons?

When you encounter a database connection error, you may not be able to understand why this problem occurs. The fact that PHP code cannot get the information needed to create a page from the MySQL database makes a WordPress database connection error. In other words, PHP code cannot connect to the MySQL database. When you encounter an error message, you will see an empty and white page. When you have resolved the error, this page, and the error message will disappear and be restored to their former state.

If you examine the causes of the WordPress database connection error, you will see that two major reasons cause this error.

  • Incorrect entry of database user information,
  • Corruption of the database,

These two are one of the most important reasons for getting a WordPress database connection error.

Incorrect Entry of Database User Information

If you enter the username and password incorrectly at the login to the administration panel, you will receive a database connection error. If you are getting this error because of the user information and password, don’t worry; this will be the easiest error to fix. Please review your login information, enter your username and password correctly, and then check again if you have received this error.

Database Corruption

When your database is corrupted, you will receive a database connection error. There can be many reasons for database corruption. The first of these is that you have installed an incompatible plugin. If you install an incompatible plugin, you will encounter a database connection error.

If the hosting /server to which your database is connected is temporarily out of service or broken, you will also receive a database connection error. Please check your WordPress hosting/server, which is connected to your website. If you have faced a problem, wait for the server to be opened again for access or to troubleshoot the failure so as not to receive a warning about a database connection error.

How Do I Prevent a Database Connection Error?

If you don’t want to get this error, the first thing you need to do is make sure that your database information is up to date; if the password and username have been changed, it will be the first process to correct from the database immediately.

Be careful not to use a plugin that is not compatible with your WordPress, and update your plugins promptly, if any.

Database Connection Error Resolution

1. Solution:

wp-config.php connects the files of your website and your database. If you have changed your database username and password, you will need to find this file. When you make changes in the wp-config.php file, it will cause you to receive this database connection error. This error will disappear when you change your password and username.

If the database connection error does not disappear when the password and username are changed, you will have to check the accuracy of the information in the wp-config.php file. The information in this file should be as follows:

define(‘DB_NAME’, ‘database-name’);

define(‘DB_USER’, ‘database-username’);

define(‘DB_PASSWORD’, ‘database-password’);

define(‘DB_HOST’, ‘localhost’);

in the wp-config.php folder you will find; “database-name”, “database-user”, “database-password” and the database host information “localhost”. The local host part may vary depending on the company of your host. Check the accuracy of other information. If there is an error in the information, you will receive a WordPress database connection error. Fix the name-user-password part.

2. Solution:

If you have corrected your database user information and password and are still receiving a database connection error, you should check all your WordPress files. Usually, all users who cannot find a solution for this problem will try to delete all WordPress files, but you will only need to find the corrupted file and fix it to solve this problem. You don’t need to delete all the files.

The files that you will edit are very important because they are the main system files, and you should be very careful when changing them. Here are the file editing steps;

  • Download your WordPress files.
  • In the local storage section, find the wp-content folder.
  • Delete the wp-config file in it.
  • With FTP, upload the remaining files to the root directory and replace old files with newly downloaded files.

If you follow these steps correctly, the database connection error will disappear.

How to Check MySQL Server?

Owners of websites with a lot of traffic are more likely to face a database connection error. It is possible that you will receive this error, especially if you are using shared hosting. It’s also possible that you may receive a database connection error if your host cannot carry the traffic that your website receives. By contacting your host, you need to find out how much traffic your MySQL server can handle.

If you want to find the source of the problem yourself without contacting your host; check other websites connected to the same hosting. If you are also getting a database connection error from these websites, your problem is definitely caused because your MySQL server cannot handle the traffic.

If you do not have another domain on the same server, go to the cPanel and click on PHPMyAdmin. You will be connected to your database. If you are able to connect, you should check the permissions of users to access your website.

If you receive an error when you are trying to connect from your cPanel;

-Access denied for user ‘foo’@’%’ (using password: YES)

That means your servers are problematic. Your servers may be broken, or the user permissions to visit may be insufficient.

If you want to check user permissions;

(When trying to get to the PHPMyAdmin panel via cPanel or do the test of testconnection.php and you still get the database connection error while doing the PHP test, please get in touch with your host.)

Create a folder named testconnection.php . Paste the following code into the file:


$link = mysql_connect(‘localhost’, ‘veritabanı_ismi’, ‘veritabanı_şifresi’);

if (!$link) {

die(‘Could not connect: ‘ . mysql_error());


echo ‘Connected successfully’;



If you have added the code to yourdomain.com/testconnection.php then go to this address. If you see “Connected successfully” when you go to the address, this shows that your users have enough permission to connect to your database of your WordPress.

If you find that user login permissions are insufficient after performing this test, you must upgrade to a higher hosting package or purchase a new server. If you do not want to do these steps yourself, you should contact your host. They will solve the problem for you easily.

What Should I Do If an Error Establishing a Database Connection Error Occurs in the /wp-admin/ Extension?

This error may also have occurred in the admin panel when you are getting a database connection error. If the database error is also received in the admin panel, you will see; One or more database tables are unavailable. The database may need to be repaired, warning. Again, you will need to repair your WordPress database. The code we will give below should be pasted into your wp-config.php file.

  • define(‘WP_ALLOW_REPAIR’, true);

Add the code, and then yourdomain.com/wp-admin/maint/repair.php check this address.

A screen like an image will appear. Click on one of the Repair Database or Repair and Optimize Database, and your database will start to be repaired.

After completing, do not forget to re-enter the wp-config.php file and delete the code you added.

WordPress database connection error is a warning that everyone has encountered at least once. Do not be worried when you face this error because you can somehow find a solution to every error in WordPress. If the database connection error needs some changes that can be made in the important files, it may scare you, and when you apply the given steps sequentially, you will find that you can actually solve it quickly.

Above, we have provided different solutions for everyone who has received a database connection error. In order to be able to solve your problem correctly, please try to understand well where the problem originated from. Then follow the instructions given completely. It is risky to make a transaction for a database error. Please make sure you do it entirely while following the stages.

0 Comment

Get More Sprit
Related Articles
Dive deeper into similar topics with our recommended articles.