Fix the Error Establishing a Database Connection in WordPress

Saturday , 1, May 2021 Leave a comment

If you face “Error establishing a database connection” in your wordpress website So you can be sure. this problem for disconnection with your database.

In this article, we will show you how to easily fix this error establishing a database connection in WordPress.

What Issue Error Establishing a Database Connection in WordPress?

This ‘Error establishing a database connection’ issue can be face by incorrect database connection in WordPress.

A database is an organized collection of structured information, or data, typically stored electronically in a software system

As a content management system(CMS) WordPress uses a database to store all website information . It then someone visits your website database connects every time

WordPress (CMS) needs the following information for connecting to the database:

  • Database name
  • Database username
  • Database password
  • Database server


This information is stored in your WordPress configuration file called wp-config.php.

If any of these items are wrong, WordPress will fail to connect database system and you will see ‘Error Establishing a Database Connection’ error.

1. Check Your WordPress Database Connection

The most common reason for database connection error in WordPress is wrong database information . Your WordPress database information are stored in the wp-config.php file. if you migration your website then this could be the most likely reason.

You’ll be looking for the following lines in the wp-config.php file.

/** The name of the database for WordPress */
define( 'DB_NAME', 'your Database name' );

/** MySQL database username */
define( 'DB_USER', 'your Database User Name' );

/** MySQL database password */
define( 'DB_PASSWORD', 'your Database User Password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

confirm the information for the database name, username, password, and database host is correct.

for confirm you need to access your cPanel

Please click to the database management page(MySQL® Databases) in your control Panel. you can find out your database name and the Privileged Users name.

Below that you will find the database users and links to change the user password.

first of all you have to know your database name, username, and password, you can change that information in wp-config.php file if needed.

After, visit your website again to see if the database connection error has gone. Even after that If you face this error, then this means that something else is wrong.

2.Check Your Database Hosting Information

If you are sure that your database name, username, and password information is correct, then you may want to make sure that you are using the correct.

Most WordPress hosting companies use localhost as your database host.However, some website hosting companies use different servers to host databases. In that case, your database host information will not be localhost.

You need to contact your WordPress hosting company to confirm your database host information.

3. Check Your Database Server is Down

If you face WordPress still can’t connect to the database but you are Sure Database connection is correct, your database server (MySQL Server) may be down.

This may be due to extra traffic on your server, your host server simply cannot handle the load (especially when you are with shared hosting)

if your website will get really slow and for some users it may even output the error. So Please contact  with your hosting provide. and ask them if your MySQL server is responsive.

If you have another websites on the same server, then you can check those sites to confirm that your SQL server is down.

you can run this code for check your MySQL connection:

<?php
$link = mysqli_connect("host Name", "User Name", "User Password", "database name");
if ($link) {
echo 'MySQL Connected successfully';
}else{
    echo 'MySQL connection error';
}
?>

If the script connected successfully, then it means that your user has sufficient permission, and there is something else that is wrong.

The Ultimate Guide to WordPress Shortcodes How To Use wp_enqueue_script () hook to Add js and CSS files after_setup_theme WordPress hook best wordpress security plugins 2021

Leave a Reply

Your email address will not be published. Required fields are marked *