[Fixed Out] Error Establishing a Database Connection in WordPress

Every wordpress user face and fix minimum one time this error " Error Establishing a Database Connection " and this error is generate when wordpress database is not connected with wordpress site correctly.

Every WordPress user face and fix minimum one time this error ” Error Establishing a Database Connection ” and this error is generated when WordPress database is not connected to WordPress site correctly. because every data of WordPress is stored in the database so while fetching data from a database with wrong database configuration this error occurs.

Why Do You Get This ERROR

There are some reasons behind ” Error Establishing a Database Connection ” . there can be a missed match communication between database connection or a corrupted files that configure the database credentials.

There are some of reasons behind the ” Error Establishing a Database Connection ” error :

  • Corrupted files in WordPress directory( mostly wp-config.php)
  • Database server is overloaded or malfunctioning
  • Incorrect database credentials (username, password, host_name, database_name)
  • Login credentials for your database are wrong.
  • The server that hosts your database is down.
  • Database is corrupted.

Note: Before you make any database changes, make sure you have whole backup of databse.

Fixing Database Connecting Issue :

1. Check Database Login Credentials

Before starting check database credentials that is right or wrong. WordPress database is configure in the wp-config.php file. in this file database and its login details is defined. this is where you specify the details for WordPress to connect your database. If you changed your root password, or the database user password, then you will need to change this file as well. First thing you should always check is if everything in your wp-config.php file is the same.

// ** 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' );

If anyone of these values is incorrect, WordPress will not be able to connect to the database. and the problem is cause this issue to fix it with right WordPress database login details.

if all the defined credentials are right and error still show then go to second method that is checking WordPress corrupted file.

2. Check WP-Config.php

Wp-config.php file contains the all the database login details and other details that overcome with installation of plugin or  by WordPress installation.

so if all the database login right then takes a lightly look on wp-config.php file. for help in the WordPress directory, there is also wp-config-sample.PHP file in the just above on wp-config.php file that contain same codes like wp-config but just in the initial condition. so open the wp-config-sample.php file and compare it with wp-config.php. and check all the basic function are defined in wp-config file same as the wp-config-sample file.

Error Establishing A Database Connection In WordPress

it is also become a great thankful solution for me on nativetechie, while i causes by below error

Fatal Error : Call to undefined function wp()

3. Modify Database

Modify database can be done by cPanel or WordPress. both method check or repair database, before taking any action please make sure you have a database backup.

Step:1 – By cPanel

Login to your cPanel and go to MySql Databases here is a section of Modify database here you can check or repair database.

Error Establishing A Database Connection In WordPress

Step:2 – By WordPress

Can you see your website normally, but get the error when trying to access wp-admin? Or maybe your website is down, but you’re getting a slightly different error when you try to login: “One or more database tables are unavailable. The database may need to be repaired.”

WordPress has a built-in way to attempt to repair your database, but you’ll have to enable this feature first. To do so, you’ll need to access your wp-config.php file, which contains your WordPress installation settings and configuration.

You can find wp-config in the your root WordPress file directory. You can access it by logging into your cPanel, selecting File Manager, and navigating to the folder where you installed WordPress.

Once you have wp-config open, add this line of code to the bottom:

define( 'WP_ALLOW_REPAIR', true );

This line will enable you to optimize and repair your database by navigating to www.yourwebsite.com/wp-admin/maint/repair.php (just replace “yourwebsite.com” with your actual URL).

Error Establishing A Database Connection In WordPress

Warning! After repair database remove the added line from wp-config.php file

4. Create new login details

Using above three methods and still error appearing then its time to make new database login credential. database login can be modified or make in the cPanel of hosting provider. database login details are database_username and database_password.

I have tried this method and got a positive result.

For making new username and password simply try below steps in cpanel.

Step:1 – Login to cPanel and Go To MySQl Databses.

Step:2 – Add New User

add new user with required form details and noted this details because now this detail will be replaced in the wp-config.php file.

Error Establishing A Database Connection In WordPress

Step:3 – Add user to database

Error Establishing A Database Connection In WordPress

Step:4 – Configure Wp-config.php

Now add new user into wp-config.php file where database details are saved.

  • Change old username with new username
  • Change old password with new password
// ** 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', 'new_username_here' );
 
/** MySQL database password */
define( 'DB_PASSWORD', 'new_password_here' );
 
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

And then run WordPress site. i hope you have overcome from this problem.

Still getting the error ? time to say hello to hosting company

If you’ve followed the above troubleshooting steps and your website is still down, it could be a problem on your host’s end. Contact your web hosting company’s support and give them all the details of the error and the troubleshooting actions you’ve taken, and they may be able to help you determine the cause of the error.


Tips for preventing this error :

  • Keep optimized your WordPress database
  • Don’t flirt unnecessary with WordPress files

Share Your Database Error Connection Story :

share your error story and help people to overcome with this preoblem.

Here’s What You Should Read Next :

[ratings]

Comments are closed.