How to Fix the WordPress Error Establishing a Database Connection

Is your WordPress website displaying the message ‘Error establishing a database connection’? It’s a fatal error that prevents users from accessing your WordPress site.

When WordPress is unable to connect to the database, this error occurs. A variety of factors can affect your WordPress database connection, making it difficult to troubleshoot for beginners.

We’ll show you how to fix the error establishing a database connection in WordPress in this article.

What Causes WordPress Error Establishing a Database Connection?

Incorrect database information in your WordPress settings, a corrupt database, or an unresponsive database server can all cause the ‘Error establishing a database connection’ issue.

A database is a piece of software that makes it simple to store, organize, and retrieve data for use in other programs.

WordPress uses a database to store all of your content and other website data as a content management system. Each time someone visits your website, it connects to the database.

For connecting to the database, WordPress requires the following information:

  • Name of the database
  • Username for the database
  • Password for the database
  • Server for databases

This data is saved in the wp-config.php file in your WordPress installation.

If any of these settings are incorrect, WordPress will be unable to connect to your database server, and you will receive the error ‘Error establishing a database connection’.

This error can also appear if the database server is down or the database files are corrupt, in addition to incorrect credentials. One of the most common WordPress mistakes is this.

Let’s take a look at how to troubleshoot the error establishing database connection issue in WordPress step by step.

1. Make sure your WordPress database credentials are correct.

Incorrect database credentials are the most common cause of database connection errors in WordPress. This is most likely the case if you have recently moved your WordPress site to a new host.

It’s the WordPress configuration file, and it’s where you’ll find all of your important WordPress settings, including database information. The wp-config.php file stores your WordPress database credentials.

If you’ve never edited a wp-config.php file before, check out our tutorial on how to edit a WordPress wp-config.php file.

The lines listed below should be found in the wp-config.php file.

You must double-check that the database name, username, password, and database host are all correct.

This information can be verified through the dashboard of your WordPress hosting account. Simply log into your hosting account and go to the database section to find MySQL databases.

You can get the name of your database and the username from here. This will take you to your hosting dashboard’s database management page.

The database users are listed below, along with links to change the user password.

You can change your database name, username, and password in your wp-config.php file if necessary once you’ve confirmed your database name, username, and password.

After that, return to your website to see if the database connection error has been resolved.

If the error is still visible, it means that something else is wrong. For more troubleshooting tips, keep reading.

Make sure your database’s host information is correct. 2. Inventive+ phrasing

If you’re confident that your database name, username, and password are correct, you should double-check that you’re using the correct database host information.

Your database host information will not be localhost in that case. Localhost is the database host used by the majority of WordPress hosting companies. Some managed WordPress hosting companies, on the other hand, host databases on separate servers.

To confirm your database host information, contact your WordPress hosting company.

3. Restore the database of WordPress

If you get a different error message in wp-admin, such as “One or more database tables are unavailable,” The database may require repairâ€, in which case you must repair your database.

Make sure it’s right before †That’s all, stop editing!â€TM wp-config.php wp-config.php wp-config.php wp-config.php wp-config.php Add the following line to your wp-config.php file to accomplish this.

Once you’ve done that, go to this page: to see the settings.

To access the database repair page, the user does not need to be logged in. Remove this code from your wp-config.php once you’ve finished repairing and optimizing your database.

4. Determine if your database server is unavailable.

If everything appears to be in order but WordPress still can’t connect to the database, it’s possible that your database server (MySQL server) is down.

Basically, your host server (especially if you’re on shared hosting) can’t handle the load. This could occur as a result of high traffic on a server.

Your site will become extremely slow, and some users may experience an error. As a result, the best thing you can do is call or chat with your hosting provider and ask if your MySQL server is responsive.

If you have other websites on the same server as your SQL server, you can check those sites to see if your SQL server is down.

If you don’t have any other sites on the same hosting account, go to your hosting dashboard and try to connect the database using phpMyAdmin.

If you’re able to connect, we’ll need to see if your database user has enough permissions. Make a new file called testconnection.php and paste the code below into it:

Replace the username and password if necessary. This file can now be uploaded to your website and accessed through a web browser.

If the script connected successfully, it means your user has enough permissions and something else is wrong.

Return to your wp-config file and double-check that everything is in order (re-scan for typos).

Other Options That Have Proven Beneficial to Users

If the above troubleshooting steps failed to resolve the database connection error on your website, you can try the following steps.

These steps, according to our users, have helped some users fix the database connection error on their websites.

1. Change the URL of your WordPress site.

Using phpMyAdmin, try changing the URL of your WordPress site. Simply select your WordPress database in phpMyAdmin from your hosting account dashboard.

Then, at the top of the page, select SQL and type the MySQL query below.

Remember to provide your own site URL and change wp_options to your own table name if the WordPress table prefix has changed.

Restarting the Web Server

Rebooting dedicated servers, local servers, and virtual private servers (VPS) is an option for users.

This will restart your web and database servers, which may resolve some of the error’s temporary issues.

3. Seek assistance

If all else fails, you might need to contact your web hosting provider. All reputable WordPress hosting companies will assist you in troubleshooting the issue, directing you in the right direction, or even resolving it for you.

The best part is that these developers have been thoroughly vetted by the Codeable team, so you can trust them. You can also hire WordPress developers from Codeable to assist you in resolving this problem at a reasonable cost.

We hope this article was helpful in resolving the WordPress database connection error. For tips on resolving WordPress issues on your own, check out our WordPress troubleshooting guide.

Please subscribe to our YouTube Channel for WordPress video tutorials if you enjoyed this article. You can also find us on social media sites such as Twitter and Facebook.

    15 Things You Must Do Before Changing WordPress Themes Checklist

    How to Fix the WordPress Error Establishing a Database Connection

  • How to Transfer Your Blog from to Correctly

    Why is it so important to build an email list today? (6 Reasons)

    Editorial Staff Information

    Over 1.3 million readers around the world rely on it. WPBeginner’s Editorial Staff is a group of WordPress experts led by Syed Balkhi.

    Thank you a lot.

    We’re glad our guide was useful.

    I’ve logged into phpMyAdmin, but I’m not sure what to do next. First and foremost, I’d like to express my gratitude for this guide! I double-checked the database information in wp-config.php and it’s all correct. I’m not a developer, just a newbie to WordPress. â€Error establishing a database connection†is a problem I’m having. I wanted to try step 4 in this guide, but I’m not sure how to do it. Is there a video of that?

    You should go to your hosting provider’s dashboard or contact them directly, and they should be able to help you out.

    It has been extremely beneficial to me. Thank you so much for this fantastic article.

    We’re glad our guide was useful.

    Thanks a lot, I tried it and it worked perfectly. I was about to give up after experiencing one problem after another, until I came across this. I had the impression that “this is it”, that this is the answer I’ve been looking for.

    We’re glad our guide was useful.

    Because I use Digital Ocean, I had to restart the DROPLET in my case.

    Thank you for letting us know what worked for you.

    When I type in the URL of my site, I get the following error:

    On your website, there was a critical error.

    Take a look at the following article for more information on this topic:

    Thank you kindly. This article is extremely beneficial.

    We’re glad you found our information useful.

    This has happened to me a few times due to a lack of space!

    Thank you for sharing that in case anyone else runs into this problem.

    This is the error I’m getting. (HY000/2002): mysqli_real_connect(): (HY000/2002): mysqli_real_connect(): (HY000/2002): mysql On line 1635 of /home/f5853789/public_html/wp-includes/wp-db.php, a connection was refused. The connection was refused.

    What am I supposed to do?

    That is a different error, and you should contact your hosting provider for assistance with that issue.

    My credentials are valid, and none of the steps outlined above appeared to be effective. I’m a newbie to WordPress, and I’m using MAMP to install it, but I’m still getting this error. I’m at a loss for what to do. The database has also been repaired.

    If you followed our guide to setting up your site on MAMP, you might want to double-check that you used the correct database prefix.

    Hello, I was just using FTP to transfer my WordPress site to a new hosting provider when this error occurred. Thank you. Is there anything else I need to do after the migration?

    Take a look at our article below for more information on moving to a new host:

    Thank you for the information. Adding the line “””define(‘WP_ALLOW_REPAIR’, true);”””””””””””””&#82 I assumed it was a problem with my hosts.

    You’re welcome; I’m glad the suggestion was useful.

    Thank you very much! Step 1 was successful for me.

    You’re welcome; we’re glad our guide was able to assist you.

    My website is intermittently returning database errors because it has exceeded the server’s maximum connection limit. How do I increase the MySQL database’s connection limit?

    To change that, you’ll need to contact your hosting provider, who should be able to help.

    So, what should I do now? I use Google Cloud for hosting and have run into this issue.

    You should be able to complete the steps outlined in this article.

    Fixing the url in sql was the solution for me. Thank you so much for taking the time to do this! Thank you very much for the code!

    Thank you for taking the time to read our guide; we hope it was useful.

    Thank you very much. Why is it displaying that to me? I’ve set up a WordPress blog. I also write posts, but it occasionally prompts me to ”please install wordpress”.

    There are a few possible causes; you should contact your hosting provider to make sure there are no issues on their end.

    My website is hosted on Amazon Web Services, and I used filezila to access the MYSQL folder, but I couldn’t find the file that contained the database username, password, and hostname. Is there a name for that particular file?

    Your wp-config.php file would contain that information.

    Thank you for your assistance.

    You are most welcome.

    Adding the repair code to my WordPress config file solved the problem. It was simple and straightforward to follow. Thank you. I enjoyed reading the article.

    Thank you for taking the time to read our advice.

    Your article was extremely beneficial. My database password had been changed, and it was no longer connecting to my blog properly, but thanks to your article, the problem has been resolved.

    We’re glad our suggestions were useful.

    Thank you for providing such a wonderful blog. Aside from that, it provides a step-by-step solution so that any reader can solve the problem with ease. It will assist WordPress beginners who are having issues with Error Establishing in the database connection.

    You’re welcome; we’re glad our articles can be of assistance.

    Thank you for providing such valuable information. Your article piqued my interest.

    You’re welcome, and we’re glad you enjoyed our article.

    After failing to resolve the database error using all of the suggested methods, I rebooted my computer. If things go wrong, you should try it as well. After forcibly shutting down my computer, I received this error.

    Thank you for sharing your successful solution.

    It was very simple to follow and only took a few minutes to complete. That’s fantastic!

    We’re glad our guide was useful.

    It was fixed in a matter of minutes. You did an excellent job. You guys have come to my aid yet again.

    We’re glad our guide was of assistance.

    Actually, after installing WordPress, I get an error message that says “Error Establishing A Database Connection,” and I’m not sure what to do. Thank you so much for making this tutorial available to us. Thank you for the article. and my site had a slew of other issues, only one of which has been resolved. Then I went to Google and found your article, which is extremely helpful to me as well as many others who are unaware of these issues.

    We’re glad our article was of assistance.

    I can’t back up my site or do any of the other things you recommend because I can’t get into the admin section of my blog. As a viewer, I can see it, but I don’t have any other options. Also, I can’t seem to find a way to contact people through WordPress! What can I do?

    If you contact your hosting provider, they should be able to help you regain access to your site. You should be able to create a manual backup using the method described here:

    Greetings, gentlemen

    For my website, I’ve now fixed it.

    To increase PHP memory, I updated my php.ini file. It was caused by a lack of PHP memory.

    Thank you for sharing your successful solution.

    My website is down due to the error “Error Establishing A Database Connection,†which I believe is related to memory. Hello, WAQAS. Could you please tell me how you increased PHP memory by updating my php.ini?

    You can find a step-by-step guide here: wp-tutorials/fix-wordpress-memory-exhausted-error-increase-php-memory/

    I’m on BlueHost and recently upgraded to WordPress 5.2, but I’m getting the dreaded error message:

    ”””&#82 WordPress requires the MySQL extension, which appears to be missing from your PHP installation. “““&#82

    Do you have any suggestions for what I could try? I tried PHP 5.6, 7.0, and 7.1, and they all gave me the same result. The error has completely blocked my site.

    If you contact BlueHost, they should be able to help you resolve the problem.

    Please assist me as I am unsure. How can I fix the Error establishing a database connection on my website? Hello, I’m in need of your assistance; could you please assist me?

    For that error, you should follow the troubleshooting steps outlined in this article.

    I believe this error occurred after I updated Xampp and created a new user with the same name. After using the “testconection.php” file and doing some more troubleshooting, I discovered that my user account was set to connect to “Any host”, which I corrected by changing it to “Localhost”. When I was using Xampp, I had the same problem.

    Thank you for letting us know what worked for you.

    …I discovered that my user account was set to connect to â€Any host,†and the problem was solved by changing it to â€Localhost,†Daniel provided the correct response in my case.

    Thank you very much!

    On my localhost, I’m getting this error.

    Both localhost and hosted sites should benefit from the techniques presented in this article.

    Thank you for writing this article. Hopefully, it will be of assistance.

    You are most welcome.

    I changed the host from 127.0.01 to localhost in the config.php file after passing the “Check your Web Host (MySQL Server)” test.

    That was effective for me.

    Thank you for sharing your answer.

    Hello, it’s only happening occasionally on my WordPress site, and when I reload the page, it works again. Please suggest a solution; at the moment, I’m using Cloudflare as a CDN and WP Rocket as a caching plugin, and the theme is Newspaper Premium.

    If it’s happening on a regular basis, you should contact your hosting provider and let them know. They should be able to help.

    This solution was extremely beneficial to me. Thank you very much.

    You are most welcome.

    â€Error establishing a database connection†was the exact error I got, but not all of the solutions you mentioned helped me.

    The other thing was that I changed the ” log on ” to user was administrator to the account I created. MySql services were disabled for me, so I went to services and set MySQL to automatic.

    My WordPress site is now up and running again.

    Thank you for sharing your solution to this problem with the rest of us.

    My strange situation is that the error establishing a database connection only affects one post in my blog, while other posts are unaffected.

    This error occurs once in a while on 3 and not always! I’m not sure why this is happening or how to fix it.

    You might try contacting your hosting provider to see if their error logs contain information that can help you figure out what’s causing the problem.

    Thank you so much, it worked perfectly. I really appreciate how short and to-the-point the video was, rather than a 7-10 minute long one.

    Adding “:3306” to the mysql address “localhost” in wp-config fixed the problem.

    It saved me a lot of time when it came to troubleshooting. Your directions are precise. Thank you so much for this article. After a web hack, I changed my database password but forgot to change the wp-config file.

    Best wishes, and may God continue to bless you! You just saved me a TON of nerves, dude! Thank you, thank you, thank you, thank you, thank you, thank you, thank

    I fixed it by deleting the MySql database and importing the backup to create a new one. I didn’t require a new WordPress installation.

    After hours of debugging and reinstalling MySQL and WP, the solution was to delete the WordPress database. I’m in the same boat! Parker, thank you so much!

    I’m not a developer or have any experience with file management, but I could easily follow your instructions. Or perhaps both! Either I’m a genius or you’re a total badass!

    I just wanted to pass this along – *It was solved for me when I changed the blank password of the localhost from the phpMyAdmin panel; the password was blank, so I suspect that was the cause, or perhaps changing the password automatically updated some necessary files. Thank you for writing this article. This error occurred while I was setting up a local WordPress instance on a Windows Wamp server.

    I checked the config.php file, but the database name on my new host is correct. The following message appears on my website: ”Error establishing a database connection”. Is there any method that can assist in resolving this issue? I’m a beginner who made the mistake of using all-in-one migration to export my website as a whole package (a.wpress file with old database information inside) rather than using separate database files and then restoring it on my new host. Respectfully, sirs, I now realize that is a terrible way to migrate my website, but I don’t have any backups.

    Hello, Frenda.

    The following are the most likely suspects. Check your database name, database password, and host.

    Thank you so much for the instructions; I followed them step by step and now my website is much better. The tutorial is extremely beneficial.

    I’m new to WordPress, so this error was a little alarming. Thank you so much for writing this article. Your suggestion to edit the wp config file immediately fixed the problem. Thank you once more! I got the error today after making a simple page edit – I wasn’t even messing around with the back end files.

Enable registration in settings - general