21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
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.

A triage-first walkthrough for the WordPress white screen caused by a failed MySQL login.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
4 min
Sections
6
Updated
14 Nov 2026
Written by
WebJi® team

What does "Error establishing a database connection" mean?

The sentence means WordPress started but MySQL refused the login stored in wp-config.php — the page is white because PHP cannot draw anything until that login works. Posts, pages, users and plugin settings all live in the database, so this is not a missing theme and not a DNS problem.

  • A wrong password, a database name missing its cPanel prefix, a stopped MySQL service or a full disk all print the same one-line error.
  • The four values to check are DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php.
  • Repairing tables is a different fix, reserved for a different message — see the triage table below.

Which screen tells you the next click?

Read the exact words on screen before editing a single 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, and phpMyAdmin failing for every database is a server problem.

Symptom-to-fix triage for the database connection error
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 from wp-config.php.
phpMyAdmin will not open, other sites fail tooStop editing and email the time — MySQL is down or refusing logins.
Site fails only at busy times, then returnsAsk about the connection cap; do not repair tables for this.
Disk usage in cPanel sits at the quotaFree space, then reload — a full disk stops MySQL writing.

How do you fix the error, step by step?

The fix is one credential change and a homepage reload: match the four database constants in wp-config.php to the MySQL user that cPanel shows on that database, and stop when the site appears. Edit the copy that is actually online — a file that never got uploaded fixes nothing.

  1. Open the homepage and /wp-admin/ in a private window. The same sentence on both confirms the MySQL login failed; if only wp-admin mentions unavailable tables, jump to the repair section instead.
  2. In cPanel, open File Manager, find the WordPress folder (usually public_html) and edit wp-config.php. Note DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.
  3. Open MySQL Databases: the database and user must be listed together, with All Privileges. cPanel stores prefix_name — the full prefixed string, 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 might be old, click Change Password beside that MySQL user, set a new one, and paste it into DB_PASSWORD only. cPanel cannot reveal the previous password, so resetting is the reliable path.
  5. Leave DB_HOST as localhost unless the host's welcome note names a different database hostname — a guessed IP fails even with the right password.
  6. Reload the homepage. It is fixed when the site shows and /wp-admin/ asks for the WordPress user, not a repair.

How do you repair the database when tables are unavailable?

Run repair only when wp-admin explicitly says one or more database tables are unavailable: add a WP_ALLOW_REPAIR line to wp-config.php, open the repair page, then remove the line immediately. While the line stays in the file, anyone who guesses the URL can run repair without logging in.

define( 'WP_ALLOW_REPAIR', true );

Place it above the "stop editing" comment, then open /wp-admin/maint/repair.php on your domain and choose Repair Database. When the report finishes, delete the line and reload the homepage. If the repair page itself cannot connect, the password is still wrong — go back to step 4 above. Check and Repair inside phpMyAdmin, and what to do when a table will not repair, is covered in the MySQL repair guide. Never import an old SQL file over the live database without a backup you can restore.

Why does the error appear only some of the time?

A site that loads, fails and loads again is running out of database connections — not holding a bad password, because a wrong password fails on every single visit. A plugin opening a new MySQL link on each page, or a traffic spike on a small plan, hits the account's connection cap.

Write down the failure times and whether other sites on the account failed too; on WordPress hosting the support desk can read the MySQL log with that timestamp. You cannot restart MySQL yourself on shared hosting, and repairing tables will not keep an intermittent error away. Note that 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 should you email support instead of editing more files?

Email support@webji.services once phpMyAdmin fails for every database or other sites on the account break at the same minute — include 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, with a published average first reply under 60 minutes; the office phone is not a support line.

Two things to try first when the site was moved from another host: the old database name often still sits in wp-config.php, so fix those four lines before asking for a new server. A restore from backup is quoted by email before any work starts, and free migration is subject to terms and approval.

FAQ

Frequently asked questions

What causes the WordPress database connection error?

WordPress could not log in to MySQL. The usual causes: a password that no longer matches, a database name missing the cPanel account prefix, DB_HOST pointing somewhere the host did not specify, a stopped database service, or a disk that reached its quota. All five print the same sentence.

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

In cPanel File Manager, edit wp-config.php in the WordPress folder and read DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Then open MySQL Databases: the database and user must appear together, carrying the account prefix. Those full prefixed strings are what must match the file.

Why does the error show only sometimes?

Because the database is accepting some visits and refusing others — a connection limit or a brief MySQL outage. A wrong password never works intermittently. Record the failure times and whether other sites failed too, then email support so the server log can be read against those timestamps.

Does this error mean my site was hacked?

Not by itself — the sentence only reports a failed MySQL login. To rule out tampering, check the modified time on wp-config.php and whether a database user you did not create is attached to the database. If other files changed without your action, clean that up after the homepage loads again.

Should DB_HOST be localhost or 127.0.0.1?

Keep whatever the host's welcome note says, which is localhost on most shared accounts. localhost and 127.0.0.1 can connect through different mechanisms, and switching between them without a note from the host usually turns a working setup into the same error on every visit.

Last editorial update: 15 November 2026.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.