Skip to content
Back to all guides

WordPress

Error establishing a database connection

When viewing your website, if you encounter the "Error Establishing a Database Connection" message on your WordPress site, it represents a fatal error that renders your site inaccessible to viewers.

The Snappyhost team Updated 3 min read
Error establishing a database connection

When viewing your website, if you encounter the "Error Establishing a Database Connection" message on your WordPress site, it represents a fatal error that renders your site inaccessible to viewers. This error occurs when a connection fails to the database, typically originating from the wp-config.php file or other related issues.

What does error establishing a database connection mean?

The underlying cause typically stems from incorrect database credentials entered in the configuration file, missing tables, or the database server refusing connection. Since WordPress is dynamically driven and stores substantial data within the database — called upon throughout pages, posts, plugins, and themes — it requires four specific elements: database name, database username, database password, and database host. If any of these fields contain errors, WordPress cannot establish a database connection. Users should verify accuracy multiple times, as typographical errors commonly trigger this issue.

Check Your WordPress Credentials

The most prevalent reason for encountering this error usually involves recently switching hosting providers. If you move to our managed WordPress hosting we do the migration and check the database connection before cutover.

How do I check my WordPress Configuration File?

Database details are stored in the wp-config.php file located in the root folder of your WordPress installation. When editing this file, you'll observe specific configuration lines. Cross-check the credentials entered against your MySQL database. For cPanel hosts, locate this information in the control panel under the 'Databases' heading, directing you to the database overview page displaying existing databases. Further down, you'll find the current users associated with your database. After confirming database name, username, password, and host (typically localhost, though this varies by hosting provider — contact your host if uncertain), you may change the database user password if needed, ensuring the updated password is used in wp-config.php's database password field. After completing these steps, revisit your site to verify the error has resolved.

Repair Your WordPress Database

If encountering the message "One or more database tables are unavailable. The database may need to be repaired" when visiting /wp-admin, it indicates a missing database table. Following site migration, tables may not have transferred during database export — double-check and obtain another export. However, you can repair the database by selecting the hyperlink on the page. Before repairing, add this line to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Important Note: This page remains accessible without login, so remove that line from the config file after completing repairs.

Check If Your Database Host is Down

If previous troubleshooting steps haven't resolved connection issues, your MySQL host may be responsible. This typically occurs during high-traffic periods when servers cannot manage traffic volume, causing intermittent database connection problems. If maintaining multiple hosting accounts on the same server running WordPress, check whether they're experiencing similar issues. Next, contact your hosting provider or check their network status page for existing problems or direct assistance.

Finally

Snappyhost invites suggestions regarding this matter via email at [email protected] for potential blog post updates benefiting other users. Direct customers can contact Snappyhost, where technical experts will provide assistance.

Hosting that keeps up

Fast UK WordPress hosting, managed for you.

LiteSpeed with LSCache, NVMe SSD, staging and daily backups, with free migration from your current host.

Read enough? Let us run the hosting for you.

Move to your own fast, isolated UK hosting with free zero-downtime migration and a real support team behind it.

Rated Excellent by UK customers

Rated Excellent on Trustpilot Excellent · 4.8 out of 5 · 84 reviews on Trustpilot

Moved to Snappy Host from Heart, and it was the best decision I have ever made! Really supportive and helpful team who helped me get my emails set up for all my customers with no hassle. 10/10.

Duncan Matthews Trustpilot

Snappy Host provide hosting with fantastic and friendly support. The range of services is great and their support is quick and helpful. I have many sites with Snappy.

Simon Clay Trustpilot

I can't rate the guys at Snappy Host highly enough. They go above and beyond to help, and I couldn't run my websites without them. Highly rated.

Customerroy charles Trustpilot

Fantastic support. Great speed at unbelievable value.

Ron Finnegan Trustpilot

I must have tried every hosting company out there. Snappy Host has delivered on their promise with excellent speeds, excellent uptime and excellent UK support. I highly recommend them 100%.

Ian Barber Trustpilot

Snappyhost are first rate. Their service is both professional and yet also personable. You know you are talking to people who know what they are doing, and they have always been on hand when we have needed advice.

Castle Steel Buildings Trustpilot

Super helpful team and always provide a five-star service. Can't recommend using them enough.

Riley Williams Trustpilot

Snappy Host is terrific. Tom, Luke and Mark all went above and beyond to help me, and fixed an issue I had had for over two years. If you want fast, helpful service as well as lightning-fast websites, look no further.

Simon M Trustpilot

I have been a customer for several years. I recently had challenges putting my website live and was helped by Tom, whose professionalism and dedication exceeded my expectations. Snappy Host sets a high standard for excellence.

PDA Trustpilot

Absolutely excellent company that goes above and beyond, and have always helped me virtually instantly when I have needed them.

DJ Eclypse Trustpilot

Our agency manages a number of sites for clients, so we need an efficient, easy-to-use platform. The team have been super helpful through set-up and migrations, all for an unbeatable price.

Josh Trustpilot

I have found the team at Snappy Host to be very helpful. A quick chat message or email and they are on the ball resolving any issues. No long, complicated process to reach them.

Segilola Salami Trustpilot

Perfect services. Reliable. Top-notch customer support.

Miroslav Trustpilot

I moved all my services to SnappyHost after a terrible experience with UK2. I can't fault them: great service, very reliable, good prices. Highly recommended.

MarkZ Trustpilot

SnappyHost support is consistently great. I have used them to host my website, which has grown substantially over the years. My site is really fast thanks to the tools they installed, and whenever there is an issue they sort it out. Amazing service.

The Professional Traveller Trustpilot

Snappy are great! They always fix our problems straightaway and without any fuss!

Anne Trustpilot