WordPress Error Establishing a Database Connection

Andrei Iordache

Andrei Iordache

WordPress Developer

? I Help People Get Found Online | WordPress Development, Core Web Vitals, Security&Maintenance

WordPress Error Establishing a Database Connection

When the website cannot connect to the database then this error occurs. Sometimes the server is unable to load correct data and becomes unresponsive. This error is called “Error Establishing a Database Connection“.

How do I fix “Error Establishing a Database Connection”?

WordPress database errors are usually caused by database details in the configuration file being incorrect. You will probably see a notice like “Error establishing a database connection” when this occurs. The easiest way to check this is to open your FTP client, I prefer FileZilla, and connecting to your site. Navigate to your root directory and find your wp-config.php file. Change the following values in that file to reflect the settings for your database. If you are not sure about these settings you can always check with your web host.

/** MySQL database name */
define('DB_NAME', 'your database name');
/** MySQL database username */
define('DB_USER', 'your database username');
/** MySQL database password */
define ('DB_PASSWORD', 'your database password');
/** MySQL hostname */
define('DB_HOST', 'your database username');

Still, having issues?

If you are sure that your database details are correct in the configuration file then your issue may be caused by some kind of server issue or corrupt database. What you can do to check this is to go to the main page of your site and check if you get the same error if you go to /wp-admin. If you see a message along the lines of “One or more database tables are unavailable. The database may need to be repaired” then there is something you can try to get this fixed. You need to add the following line to your wp-config.php file, add the code anywhere there is an empty line.

define('WP_ALLOW_REPAIR', true);

Now reload the /wp-admin page and it should present you with the option to repair the database. Click repair and let it run until finished and check if this solves your issue. You may want to remove the above code after you are done.

The advanced way to fix this error (don’t do it if you’re a newbie):

A few years ago, I ran into this problem after I accidentally removed the URL from the settings (it happens to everyone).

I fixed the problem by logging into phpMyAdmin (search it in the cPanel). If you have more sites installed, search for your site’s database (the one with the error), and in your Database go to the table WP_OPTIONS (If you don’t know what is the name of the database for that website, go to WP-CONFIG.PHP and you’ll find the database name there).

When in here click browse, this lists all the information.

You will notice the site URL value is blank.

Click the edit button (it looks like a pencil) and re-input your URL into the Value text area and click save.

Submit Your Guest Post

Previous Post
WordPress Update Failed Error
Next Post
WordPress Memory Exhausted Error
Lusi StudiosLusi Studios
15:32 22 Jun 22
Andrei did an amazing job! He helped in a very rushed time and he excelled at everything. Thanks again!
I am grateful and I would to thank Websites Seller for their support in site recovery and site transfer. Websites Seller just saved my business. Thank you!
Wouter GhysensWouter Ghysens
11:52 10 Sep 21
Looking for a Wordpress transfer from site A to site B, I found back Andrei from Wesites Seller on Google.He was very proactive in his approach, came with hundreds of ideas and lifetime experiences from other migrations. He knows the wordpress, the hosting and php database as the back of his pocket.And we worked out this migration very smooth. Together we solved it, and myself and my business are very pleased with his approach.100% recommendation & kudo's from out of Belgium!
Ioachim CiobanuIoachim Ciobanu
18:39 14 Jul 21
Websites Seller built my resume site. Deliverables were quickly completed, and I was asked for my feedback at each stage of development. All feedback I gave was implemented in a short time.Another great thing is that he comes with smart solutions, regarding stuff which I didn't initially think of (site security, Google site speed optimization and so on). Basically, he was great, staying in touch, keeping me updated and paid attention to what was most important for my site.Overall, I am very happy with the work done. I highly recommend this developer!
K CollinsK Collins
09:11 19 May 21
I needed help with website speed - to improve my core web vitals - without compromising the usability of my site. Andrei was extremely responsive, proactive and fast. And more importantly, he increased by website speed. Highly recommend him, and I will be using him going forward on all my projects.

Submit Your Guest Post


WordPress Website Maintenance Services

WordPress Maintenance Services

WordPress website maintenance service that provides cloud backups, emergency support, weekly website updates, speed and many more.


WordPress Migration Service

Safely transfer your WordPress website to a new location for $75. … Migrate your website to its new host.


Lawyer Web Design

We specializes in website design, Internet marketing and SEO for lawyers and attorneys throughout the Europe and US.