Fix Error Establishing a Database Connection in WordPress Here!!

  • Written By  

  • Updated on July 17th, 2020

Do you encounter with the “error establishing a database connection in WordPress” error in your Worpress? Then learn here more about it. This guide gives many solutions to fix such kind of errors.

This database error in WordPress is possibly one of the most popular and terrifying bugs of WordPress users may experience. It ‘s certainly a similar connection to the white screen of death (WSOD). This bug means that your website no longer interacts or has access to your WordPress servers. It makes the entire site down.

Let’s understand this WordPress database connection error in detail.

What is the meaning of Error Establishing a Database Connection In WordPress?

Generally, MySQL database of Worpress includes all content on the WordPress blog. All the post data, page data, meta information, plugin settings, login information, etc., are saved in your MySQL database. Some information is not stored on the WordPress database is media content including images and theme/plugin/core files.

When this doesn’t function properly for any reason, the error setting up a database contact message. The whole page is empty as no data can be accessed to make the file, as the connection is not working properly. Even so, visitors couldn’t see this error on the front end immediately. It’s because your site will most likely always work from the cache before it expires.

Now, let us talk about the main reasons due to which this database connection error occurs. 

Users-Made Reasons behind the WordPress Database Connection

  • Compromised WordPress files: WordPress core files may get compromised as a result of a bad update, among many others. That can include items like unsuccessful plugin updates, themes, etc.
  • Inaccurate login credentials: In order to access the website, WordPress requires a different username and password. When they have modified for whatever cause, WordPress will no longer be possible to get something from the site.
  • Network Server Down: In some instances, the webserver that holds the website information is operating on a separate machine than the database. And the specific database server may be down for some purpose.
  • Damaged Database: It may be the cause of a malicious plugin mixing up the database internally, a hacker attempt, a broken theme, and much more.
  • High-Amount Traffic: Sometimes a good thing may cause another new problem. This may result in an unresponsive database connection.

After knowing some user mistakes that generate WP error establishing a database connection, let’s move ahead to check its solution.

DIY Tricks to Fix Error Establishing a Database Connection in WordPress

Method 1: Make Changes in WordPress Credentials

All the WordPress database credentials generally are stored in the wp-config.php file. Basically, this file consists of essential WordPress settings, including database information.

You can see some of the lines as given below in your wp-config.php file.

  1. // ** MySQL settings – You can get this info from your web host ** //
  2. /** The name of the database for WordPress */
  3. define( ‘DB_NAME’, ‘database_name_here’ );
  4. /** MySQL database username */
  5. define( ‘DB_USER’, ‘username_here’ );
  6. /** MySQL database password */
  7. define( ‘DB_PASSWORD’, ‘password_here’ );
  8. /** MySQL hostname */
  9. define( ‘DB_HOST’, ‘localhost’ );

You have to ensure that all the data filled in the database name, username, password, and database host is accurate.

Steps:

  • Verify this data from your WordPress dashboard hosting account. Only sign in to your hosting account and select MySQL databases underneath the database heading.
error establishing a database connection in WordPress
  • It will bring you to the database management page of your Dashboard hosting site. After this, you can find out the database name and the user name.
error establishing a database connection in WordPress
  • Now, you can view the users of the database and the links to make changes in the password of the account.
  • When your database name, username, and password have been verified, you can update the data in your wp-config.php file if required.
  • In the end, try to visit your website again to see if the WordPress database connection error now solved or not.

If not solved then visit the next method. 

Method 2: Test to see if your database server is down

When all appears to be right and WordPress is still unable to connect to the database. Because of this, the database server (MySQL server) can be down.

  1. This might occur due to massive server traffic. Essentially, your host server can’t control the huge pile (especially when you’re on shared hosting).
  2. Your site is going to get very sluggish, and some users can even get an error. And the only thing you need to do is have a phone or live chat with your hosting company. Also, ask them if your MySQL server is open.
  3. Also, you can test those pages to verify that your SQL server is down if you have other websites operating in the same domain.
  4. Then, just go to your hosting dashboard and try accessing phpMyAdmin and connecting it to the database. But this is the case when you don’t have any other site on the very same hosting account.
  5. If you really can connect, we have to verify that your database user has appropriate permission. Build a new document named testconnection.php and insert the following code into it:
  1. <?php
  2. $link = mysqli_connect(‘localhost’, ‘username’, ‘password’);
  3. if (!$link) {
  4. die(‘Could not connect: ‘ . mysqli_error());
  5. }
  6. echo ‘Connected successfully’;
  7. mysqli_close($link);
  8. ?>

Notice: Please ensure that the username and password are replaced. You could now add this file to your website and view it via a web browser.

When the script is linked successfully, it means that the user has appropriate permission. It means there is something else that is incorrect.

Method 3: Verify your Host Database for Data

If you really are comfortable knowing that your database name, username, and password information is correct, you might like to ensure to fill appropriate host database information.

Most WordPress hosting providers use localhost as their host database. Even so, a few other maintained WordPress hosting companies are using separate servers to host databases. Within this case, the host database details would not be a local server.

Then, you have to contact your WordPress hosting company to validate your host database details.

Method 4: Make Changes in WordPress Domain URL 

  • Using phpMyAdmin to begin modifying the WordPress account URL. Just open phpMyAdmin from your hosting account dashboard and pick your WordPress folder.
error establishing a database connection in WordPress
  • Press the SQL menu available on the top and type the following MySQL query:

UPDATE wp_options SET option_value=’YOUR_SITE_URL’ WHERE option_name=’siteurl’

Notice: Make sure to give your original site URL and adjust wp options to your own table name, as you might have modified the WordPress table prefix.

During fixing the MySQL connection with WordPress, you might have to face some corruption issues with it. So, you can make a quick recovery of My SQL database by MySQL Recovery Tool. It makes the corrupted file healthier or normal as the previous one. Via, this tool one can easily recover corrupted MySQL Database.

Conclusion

Here, we focused on fixing the error Establishing a Database Connection in WordPress. Many reasons and solutions for it are described here. I Hope, you liked this article in fixing your problem of WordPress. 

About The Author:

Pallavi is a content writer in the field of data recovery and email migration. She has a passion for creating engaging and thought-provoking content. With several years of experience in the field, she has developed a deep understanding of various writing styles and formats,

Related Post

© Copyrights 2017-2024 Database File Recovery. All Rights Reserved.