Blog · WebJi® India

Error Establishing a Database Connection

Quick answer: Error establishing a database connection means WordPress reached PHP but MySQL rejected the login. Match DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php to the user on that database in cPanel. Repair tables only if wp-admin says they are unavailable. The site is fixed when the homepage loads.
✓ In business since 2005✓ INR + GST billing✓ 24/7 Email Support — avg reply < 60 min
Indian designers reviewing website wireframes together on a studio monitor — error establishing database connection fix

What error establishing a database connection means

Error establishing a database connection means WordPress started and MySQL refused the login stored in wp-config.php. Match DB_NAME, DB_USER, DB_PASSWORD and DB_HOST to the MySQL user that cPanel shows on that database. Repair tables only when wp-admin says they are unavailable. The homepage is fixed when the site loads.

  • The white page is a failed MySQL login. It is not a missing theme or a DNS miss.
  • Posts, users and plugin settings live in that database, so PHP cannot draw a page until the login works.
  • A wrong password, a name missing its cPanel prefix, a stopped MySQL service, or a full disk all print the same sentence.

How to fix error establishing a database connection

How to fix error establishing a database connection is one change, then a reload of the homepage. Stop when the site appears. Edit the copy that is actually online, not a file that never got uploaded.

  1. Open the homepage and /wp-admin/ in a private window. The same sentence on both means the MySQL login failed. If only wp-admin says one or more database tables are unavailable, use the repair section and skip the password reset.
  2. In cPanel, open File Manager, go to the WordPress folder (public_html, or the subfolder the domain uses) and edit wp-config.php. Copy DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.
  3. Open MySQL Databases. The database and the user must be listed together, and the user needs All Privileges. cPanel stores prefix_name, not the short name from the create form. The cPanel MySQL database guide shows how to attach the user if that row is missing.
  4. If the password in the file might be old, click Change Password beside that MySQL user, set a new one, and paste it into DB_PASSWORD only. Save wp-config.php. cPanel will not show the previous password.
  5. Leave DB_HOST as localhost unless the host wrote a different database hostname on the welcome note. A guessed IP fails even when the password is right.
  6. Reload the homepage. It is fixed when the site shows and /wp-admin/ asks for the WordPress user, not for a database repair.

Which screen tells you the next click

Read the words on the screen before you edit a second file. The same sentence on the homepage and in wp-admin is a login problem. A different sentence in wp-admin is a table problem. phpMyAdmin failing for every database is a server problem.

What you seeWhat to change
Same sentence on the homepage and wp-adminReset the MySQL user password and paste it into DB_PASSWORD.
wp-admin says one or more tables are unavailableRun the repair page, then delete the repair line.
phpMyAdmin will not open, and other sites fail tooStop editing and email the time. MySQL is down or refusing logins.
The site fails only at busy times, then returnsAsk about the connection cap. Do not repair tables for this.
Disk usage in cPanel is at the quotaFree space, then reload. A full disk stops MySQL from writing.

Repair the database when tables are unavailable

Use repair only when wp-admin says one or more database tables are unavailable. Above the line that says to stop editing, add define('WP_ALLOW_REPAIR', true); then open /wp-admin/maint/repair.php on your domain and choose Repair Database.

When the report finishes, delete that line from wp-config.php and reload the homepage. While the line stays, anyone who can guess the URL can run repair without logging in. If the repair page itself cannot connect, the password is still wrong.

Check and Repair inside phpMyAdmin, and what to do when a table will not repair, is in the MySQL repair guide. Do not import an old SQL file over the live database until you have a backup you can restore.

When the error shows only some of the time

A site that loads, fails, then loads again is running out of connections, not holding a bad password. A wrong password fails on every visit. A plugin that opens a new MySQL link on each page, or a traffic spike on a small plan, hits the account cap.

Write down the time and whether other sites on the account failed too. On WordPress hosting the desk can read the MySQL log. You cannot restart MySQL yourself on shared hosting. Repairing tables will not keep an intermittent error away.

DB_HOST set to localhost on a live account means the database is on the same server. It is not a local install on your laptop, and changing it to 127.0.0.1 without a note from the host usually makes the error permanent.

When to email support

Email support@webji.services with the domain, the time, whether phpMyAdmin opens, and whether you already reset the MySQL password. Support replies by email 24/7 in Hindi and English, and the average first reply is under 60 minutes. The office phone is not a support line.

A site moved from another host often still has the old database name in wp-config.php. Fix those four lines before you ask for a new server. A restore from backup is quoted by email before any work starts. Free migration is subject to terms and approval.

Frequently Asked Questions

How do I fix error establishing a database connection?

Open wp-config.php and compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST with the MySQL user on that database in cPanel. If the password may be old, reset it in cPanel and paste the new one into DB_PASSWORD. Repair tables only when wp-admin says they are unavailable.

What causes the WordPress database connection error?

WordPress could not log in to MySQL. Usual causes are a password that no longer matches, a database name missing the cPanel prefix, DB_HOST set to a host you were not given, a stopped database service, or a disk that is full.

How do I check database credentials in wp-config.php?

In cPanel File Manager, edit wp-config.php in the WordPress folder. Read DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. In MySQL Databases the same database and user are listed with the account prefix. Those full strings have to match the file.

Why does this error show only sometimes?

The database is accepting some visits and refusing others. That is a connection limit or a short MySQL outage, not a bad password, because a wrong password fails every time. Email the times it failed so support can read the server log.

How do I repair a corrupted WordPress database?

Do this only if wp-admin says one or more database tables are unavailable. Add define('WP_ALLOW_REPAIR', true); to wp-config.php, open /wp-admin/maint/repair.php, run Repair Database, then delete that line. If the repair page cannot connect, fix the password first.

Does this error mean the site was hacked?

Not by itself. The sentence only means the MySQL login failed. Check the modified time on wp-config.php and whether a database user you did not create is attached. If other files changed and you did not update them, clean that up after the homepage loads.

Need help with this?

WebJi® support does it for you — free. Talk to our Jaipur team →