WordPress error establishing a database connection

2 Quick Ways to Big Fixes

Learn how to fix the ‘WordPress error establishing a database connection’ with our step-by-step guide. Ensure your website runs smoothly.

I want a free help
Drop us an email

help@wpcare.ai

Give us a ring

+420 731 115 117

Book free call

click here

Hop onto Discord

click to join

Messages for this Error

Quick Explanation of the Error

The “WordPress error establishing a database connection” occurs whenever WordPress cannot connect to the database. This issue may be caused by incorrect login credentials or a misconfigured server.

The same error will also happen if the database is unavailable, whether due to the server being offline or inaccessible, commonly due to a firewall or network issue.

Can’t resolve the issue “WordPress error establishing a database connection” or don’t want to deal with it?

Get you website fixed today!

How to Identify and Fix the Problem

As a first step to resolve “WordPress error establishing a database connection”, ensure that your database details in the wp-config.php file are correct.

Locate the wp-config.php File

Log in to your FTP account (or file manager provided by your hosting provider) and locate the wp-config.php file.

Open the File

Open the wp-config.php file and find the section labeled: “Database settings.”

Compare Your Settings

Compare the settings in the file with the details provided by your hosting provider. Be careful to avoid typos or trailing spaces in the entries.

You can usually find your database details in your hosting control panel or the email you received when the database was set up.

The fields to check are:

DB_NAMEDatabase name
DB_USERDatabase username (often the same as DB_NAME)
DB_PASSWORDDatabase password
DB_HOSTThe server hosting the database, often “localhost”, meaning the same machine as the website.
Table: Description of database configuration items in wp-config.php

If your hosting provider gives you multiple types of MySQL access, ensure you use one with full permissions.

Contact Your Hosting Provider

If the details are correct, contact your hosting provider to confirm that the MySQL server is operational and accessible. Alternatively, you can reset the database password via your hosting control panel and update it in the wp-config.php file. If the issue persists, your hosting support team may need to intervene.

This should help you resolve the “WordPress error establishing a database connection”.

Can’t resolve the issue “WordPress error establishing a database connection” or don’t want to deal with it?

Get you website fixed today!

Advanced Solutions for Troubleshooting

You can perform additional checks to resolve the “WordPress error establishing a database connection” if you manage your server or fully control your MySQL instance. These steps assume familiarity with your server and command-line usage.

Verify the MySQL Server Is Running

Log in to your server via SSH and ensure the MySQL service is active.

For both Debian/Ubuntu and CentOS, you can use the following command:

service mysql status

The service should show a status of “Active, running.”:

WordPress error establishing a database connection mysql service

Check Database Server Accessibility

If your database server is on a different machine than your web server, test connectivity from your web server to the database server using a command like:

mysql -u your_user_name_for_wordpress -h your_db_server_ip_or_url -p

You will either be prompted for the password and connected or receive a connection error.

Verify User Permissions

If the service is running and the database is accessible, ensure the database user has sufficient permissions for WordPress.

Log in to your MySQL server with root privileges and run the following commands:

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, INDEX, DROP, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES ON your_db_name_for_wordpress.* TO your_user_name_for_wordpress@'localhost';

And then:

FLUSH PRIVILEGES;

Replace the placeholders with your actual database credentials.

Be cautious when executing commands to ensure they are appropriate for your environment.

Can’t resolve the issue “WordPress error establishing a database connection” or don’t want to deal with it?

Get you website fixed today!

More errors that you can solve

  • There has been a critical error on this website
  • WordPress error establishing a database connection
  • WordPress repair database
  • Your php installation appears to be missing the MySQL extension which is required by WordPress

Free WordPress help

From issues, speed, and automation to increasing profits… 100% free, no strings attached, no pressure.

Contact our WordPress Care Support

Get ready (perhaps for the first time) to understand a techie. For free. Clearly. Expertly.

Because we are WordPress Care (how do our services differ from regular hosting?). Share your number, and we’ll call you. Or reach out to us through chat, Discord, email, or phone, whichever you prefer.

Popup