Did you find an ‘Error Establishing a database connection WordPress‘ on your WordPress website? it’s a fatal error that creates your WordPress website inaccessible to the users.

This error occurs when WordPress is unable to form a connection to the database. Different types of content or symbols can affect your WordPress database connection which makes it harder for newcomers to solve problems.

In this article, we’ll show you ways to simply fix the error establishing a database connection in WordPress.

What Causes Error Establishing a database connection wordpress?

The ‘Error Establishing a database connection wordpress‘ problem is most often caused by your WordPress settings, a malicious database, or an incorrect database on an unneeded database server.

What Causes Error Establishing a Database Connection in WordPress

A database may be a software which makes it easy to store, organize, and retrieve data into other software.

As a content management system, WordPress uses a database to store all of your content and other website data. It then connects to the database whenever someone visits your website.

WordPress needs the subsequent information for connecting to the database:

 Database name

 Database username

 Database password

 Database server

This information is stored in the configuration file in your WordPress database in the WP-Configuration file. If any of those items are incorrect, WordPress would fail to attach to your database server, and you’ll see the ‘Error establishing a database connection’ error.

It is one among the foremost common WordPress errors. aside from incorrect credentials, this error also can appear if the database server is down, or the database files are corrupt.

Let’s take a glance at the way to fix error establishing database connection issue in WordPress with step by step troubleshooting.

1. Check Your WordPress Database Credentials

The most common reason for Error Establishing a database connection WordPress is wrong database credentials. If you’ve got recently moved your WordPress site to a replacement host, then this might be the foremost likely reason.

Your WordPress database credentials are stored within the wp-config.php file. it’s the WordPress configuration file that contains important WordPress settings including database information.

If you’ve got not edited wp-config.php file before, then take a glance at our guide the way to edit wp-config.php enter WordPress.

You’ll be trying to find the subsequent lines within the wp-config.php file.

You’ll be trying to find the subsequent lines within the wp-config.php file.

ou got to confirm that the knowledge for the database name, username, password, and database host is correct.

You can verify this information from your WordPress site’s hosting account dashboard. Simply log in to your hosting account and click on on MySQL databases under the database section.

This will take you to the management page in your hosting dashboad. From here, you’ll determine your database name and therefore the username.

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

Once you’ve got confirmed your database name, username, and password, you’ll change that information in your wp-config.php file if needed.

After that, try visiting your website again to ascertain if the Error Establishing a database connection WordPress has gone.

If you’ll still see the error, then this suggests that something else is wrong. Continue reading for more troubleshooting steps.

2. Check Your Database Host Information

If you’re confident that your database name, username, and password information is correct, then you’ll want to form sure that you simply are using the right database host information.

Most WordPress hosting companies use localhost as the database host for your website. However, some managed WordPress hosting companies use separate servers to provide database hosting services. therein case, your database host information won’t be localhost.

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

3. Repair WordPress Database

If you’re getting a special error on the wp-admin, as an example , something like “One or more database tables are unavailable. May need to fix the database “, then you want to repair your database.

You can do that by adding the subsequent line in your wp-config.php file. confirm to feature it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

1define(‘WP_ALLOW_REPAIR’, true);

Once you’ve got done that, you’ll see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

Note: the user doesn’t got to be logged in to access the database repair page. Once you’re done repairing and optimizing your database, confirm to get rid of this code from your wp-config.php.

4. Check if Your Database Server is Down

If everything seems to be correct, and WordPress still cannot hook up with the database, then your database server (MySQL server) could also be down.

This could happen thanks to heavy traffic on a server. Basically, your host server just cannot handle the load (especially once you are on shared hosting).

Your site will get really slow and for a few users it’s going to even output the error. therefore the neatest thing you ought to do is get on the phone or live chat together with your hosting provider and ask them if your MySQL server is responsive.

If you’ve got other websites running on an equivalent server, then you’ll check those sites to verify that your SQL server is down.

If you are doing not have the other site on an equivalent hosting account, then simply attend your hosting dashboard and check out to access phpMyAdmin and connect the database.

If you’ll connect, then we’d like to verify if your database user has sufficient permission. Create a replacement file called testconnection.php and paste the subsequent code in it:

Make sure to exchange the username and password. you’ll now upload this file to your website and access it via browser .

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

Go back to your wp-config file to form sure that everything there’s correct (re-scan for typos).

Other Solutions That Have Worked for Users

If the above-mentioned troubleshooting tips did not fix the Error Establishing a database connection WordPress on your website, then you’ll try these additional steps.

As reported by our users, these steps have helped some users resolve the Error Establishing a database connection WordPress on their websites.

1. Update WordPress Site URL

Try updating the WordPress site URL using phpMyAdmin. Simply access phpMyAdmin from your hosting account dashboard, and choose your WordPress database.

After that click on the SQL menu on the highest and enter the subsequent MySQL query.

UPDATE wp_options

Don’t forget to supply your own site URL and alter wp_options to your own table name as you’ll have changed the WordPress table prefix.

2. Rebooting Web Server

Users on dedicated servers, local servers, and virtual private servers (VPS) can try rebooting their servers.

This will restart your web and database server which can fix some temporary glitches causing the error.

3. invite help

If everything else fails, then you’ll got to contact your web hosting company. All good WordPress hosting companies will assist you troubleshoot the matter , point you within the right direction, or maybe fix it for you.

You can also hire WordPress developers from Codeable which will assist you to fix this issue for reasonable rates. the simplest part is that these developers are highly-vetted by the Codeable team, so you recognize they will be trusted.

We hope this text helped you fix the error establishing a database connection in WordPress. you’ll also want to ascertain our WordPress troubleshooting guide for recommendations on resolving WordPress issues on your own.