You open your website, excited to see how it’s doing. But instead, you see a white screen with the message: “Error Establishing a Database Connection.”
You try refreshing the page, but nothing works. Still the website is down, and you start to worry.
Don’t panic – this is a common issue, and it can be fixed. Follow the steps, and your site will be back online soon.
Now imagine your visitor opens your website. They want to read your blog or buy something.
Instead, they see the error: “Error Establishing a Database Connection.”
What is this problem?
This happens when WordPress cannot connect to the database. The reasons could be wrong settings, server issues, or broken files.
It sounds complicated, but the good news is it’s usually caused by a few common issues. With some simple troubleshooting, you can fix it.
In this guide we will get all details:
.
- The most common causes.
- Step-by-step fixes to solve the problem.
Before proceeding further let’s understand
How wordpress work
WordPress uses two key technologies:
- MySQL: To store and manage website data.
- PHP: To retrieve data from the database and show it to visitors.
When someone enters your website URL, WordPress uses PHP to get the data from MySQL and deliver it to their browser.
If this connection breaks for any reason, you’ll see the error: “Error Establishing a Database Connection.”
The most common causes
- No Database at source – WordPress can’t find your database. It might happen that you have installed wordpress and forget to create a database for the same.
- Login Details Changed: Your username or password might have been changed, even if you didn’t do it.
- Corrupted Database: A poorly coded plugin can damage your database.
- Heavy Traffic: Too many visitors at once may overload your server.
- Hosting Issues: Your web hosting provider might be facing problems with the database.
- Server Out of Memory:When your server runs out of memory, MySQL crashes.
- Full Disk: A full disk can also cause this error.
How to Fix “Error Establishing a Database Connection.”
I advise you to take a backup of the database before performing any task.
- Go to your hosting service provider console and search for Database. Here I am using Kloudbean’s console.
- Click on the backup option and create a backup file of the application.
Now we will try to fix the problem based upon the problem.
Condition 1: Check for Database
Navigate to http://localhost/phpmyadmin. In the Kloudbean console you can directly launch the database in a single click.
Search for the database. If not found, create a new database for the application. Click on create a new database where it says choose a name for your database.
Next, open up wp-config.php in the root of your wordpress folder, and update the four values shown below to reflect your new database.
The default credentials for your newly created database are:
- DB_NAME: Your chosen db name (case sensitive)
- DB_USERNAME: root
- DB_PASSWORD: “”
- DB_HOST: localhost
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define( 'DB_NAME', 'database_name_here' ); /** MySQL database username */ define( 'DB_USER', 'username_here' ); /** MySQL database password */ define( 'DB_PASSWORD', 'password_here' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' ); #sometimes it may be IP address
You can change the database name and password as well.
Go to the application console. In the right side of the dashboard you will see a Database access.
Click on the edit button and you will able to edit the db_name and db_password.
If database exist then check
Condition 2: Login Credentials
Sometimes, your database login settings can stop working if you update user information or database details without properly updating the wp-config.php file.
The wp-config.php file is crucial for WordPress. It stores all the database connection details.
Inside this file, you’ll find four key variables:
- Database Name
- Database Username
- Database Password
- Database Host (usually “localhost” or an IP address).
These details must match your database credentials for the connection to work.
Once you fill all the credentials, save the file and refresh the URL in the browser. It will work.
Condition 3: Check Memory consumption
If the database details are correct but the problem is still there, check the server load and memory size. Sometimes, high memory usage stops the site from connecting to the database. Upgrading the server with more memory is a good idea to avoid running out of memory.
You can confirm that your server is running out of memory by looking for the message “Out of memory” in the log file /var/log/syslog.
Condition 4: Corrupted Plugin or Theme
Outdated plugins or themes can corrupt your WordPress files, especially if an update fails or an external server is unreachable.
- Identify the problematic plugin or theme.
- Deactivate it to resolve the issue.