"Error establishing a database connection" is the WordPress white screen every site owner dreads: no posts, no admin login, just that one line of text. On Ultra Web Hosting it almost always comes down to something small and fixable, usually a credential in wp-config.php that no longer matches the database. This guide walks through every cause in order, from the wrong database password to a corrupted table, with the exact wp-config.php lines to check and the safe way to run a repair.
- What the Error Actually Means
- The Most Common Cause: wp-config.php Credentials
- Confirm the Credentials Against cPanel
- DB_HOST Should Be localhost
- Verify the User Is Attached to the Database
- Check the Database Itself in phpMyAdmin
- Repair a Corrupted Database
- One Page Works, Another Fails
- Resource Limits and Too Many Connections
- After a Migration, and When to Open a Ticket
Nine Times Out of Ten, It Is the Password
WordPress stores four database settings in wp-config.php. If any one of them stops matching what the database expects, every page returns the connection error. The fix is usually to re-check those four lines and reset the database user's password in cPanel.
- Confirm
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOST - On our shared hosting,
DB_HOSTislocalhost - Make sure the user is attached to the database with privileges
- Only after credentials check out do you look at corruption or limits
Check Credentials Before You Touch Anything Else
The temptation is to jump straight to "repair my database" or assume the server is down. Resist it. A corrupted database is real but uncommon, while a mismatched password after a migration or a password change is the everyday cause. Work Sections 02 through 05 first. If the credentials are provably correct and the user is linked with privileges, then move on to corruption and resource limits.
- Wrong credentials: most common, fixed in cPanel in minutes
- Corrupted database: less common, fixed with the WordPress repair tool
- Diagnose in that order and you save yourself a lot of guessing
01. What the Error Actually Means
Every WordPress page is built on the fly by querying a MySQL/MariaDB database: your posts, pages, settings, users, and plugin data all live there. When you load a page, WordPress opens a connection to that database using the credentials in wp-config.php, runs its queries, and renders the result. "Error establishing a database connection" means that first step failed. WordPress could not reach the database, or it reached it but was rejected, so there is nothing to render and you get the bare error message instead of a page.
Because the front end and the admin area both need the database, a true connection failure takes down the whole site, including /wp-admin. That is actually useful information: if the error appears everywhere, the problem is the connection itself (credentials, host, or the database server). If it appears on only some pages, you are likely looking at a corrupted table, which we cover in Section 08.
This is a WordPress-specific message generated by WordPress itself. The underlying issue is a general MySQL/MariaDB connectivity or authentication problem, which is why a lot of this guide applies to any application on our hosting, not just WordPress.
02. The Most Common Cause: wp-config.php Credentials
WordPress keeps its database settings in a single file at the root of your site called wp-config.php. Open it in cPanel File Manager (Edit) or over SFTP and look for these four lines near the top:
define( 'DB_NAME', 'user_wp123' );
define( 'DB_USER', 'user_wpuser' );
define( 'DB_PASSWORD', 'your-database-password' );
define( 'DB_HOST', 'localhost' );
Any one of these being wrong produces the connection error. The usual triggers are a site migration (the new account uses different database and user names), a password change (someone reset the database user's password in cPanel but did not update wp-config.php), or a typo introduced while editing the file. Read each value carefully:
- DB_NAME is the exact database name, including the account prefix (on our hosting it looks like
cpaneluser_dbname). - DB_USER is the database user, also prefixed (
cpaneluser_dbuser). This is not your cPanel login or your WordPress admin login. - DB_PASSWORD is the password for that database user. It is case sensitive and often contains symbols, so watch for a missed character.
- DB_HOST is where the database lives. On our shared hosting this is
localhost(see Section 04).
Before you edit wp-config.php, download a copy or duplicate it in File Manager as wp-config.php.bak. A single stray quote or missing semicolon in this file will take the whole site offline, and having the original to fall back on turns a mistake into a thirty-second recovery.
03. Confirm the Credentials Against cPanel
You now know what wp-config.php claims. Next, confirm those values against the source of truth, which is cPanel MySQL Databases.
- Log in to cPanel and open MySQL Databases (under the Databases section).
- Under Current Databases, confirm a database exists whose name matches
DB_NAMEexactly, prefix and all. - Under Current Users, confirm a user exists whose name matches
DB_USERexactly. - If either name does not match wp-config.php, correct wp-config.php to match cPanel (do not rename the database, just fix the config line).
- For the password, you cannot read it back in cPanel, so if there is any doubt, reset it. Under Current Users, click the user, set a new password, then paste that exact password into
DB_PASSWORDin wp-config.php.
Resetting the password and updating wp-config.php in the same sitting is the single most reliable fix, because it removes the one value you cannot otherwise verify. Use a password without spaces to avoid copy-paste surprises.
If you would rather test the credentials outside WordPress first, try logging in to phpMyAdmin using the DB_USER and DB_PASSWORD from wp-config.php. If phpMyAdmin rejects them, WordPress will too, and you have confirmed the problem is authentication. Our "How to Manage Your Database with phpMyAdmin" guide walks through logging in.
04. DB_HOST Should Be localhost
On Ultra Web Hosting shared plans, the database server runs on the same machine as your site, so WordPress connects to it locally. The correct value is:
define( 'DB_HOST', 'localhost' );
Do not use 127.0.0.1, and do not use a remote hostname or IP unless our support team told you to (which only happens on specific VPS or dedicated setups). A migrated site frequently arrives with DB_HOST pointing at the old host's database server, which of course is unreachable from here, and that alone produces the connection error even when the name, user, and password are perfect.
With DB_HOST set to localhost, WordPress connects over the local socket and the port is not something you normally set. If you have inherited a config that appends a port (for example localhost:3306) and it is failing, drop back to plain localhost. For what port MariaDB/MySQL actually listens on and when it matters, see article 121.
05. Verify the User Is Attached to the Database
A database user and a database are two separate objects in cPanel. A user only has access to a database it has been explicitly added to, with privileges granted. If DB_NAME and DB_USER both exist and the password is right, but the user was never linked to that database (or lost its privileges during a migration), the connection is rejected exactly the same way a bad password is.
- In cPanel MySQL Databases, scroll to Add User To Database.
- Select your
DB_USERand yourDB_NAMEfrom the two dropdowns and click Add. - On the privileges screen, tick ALL PRIVILEGES, then click Make Changes.
- If the user was already attached, cPanel will tell you so, and this step simply confirms the privileges are in place.
Granting all privileges is correct for a normal WordPress install, because WordPress needs to read, write, and alter its own tables. The full walkthrough of linking a user, including the privilege list, is in article 122.
When in doubt after a migration, do all three at once: reset the user's password, re-add the user to the database with all privileges, and update DB_PASSWORD in wp-config.php. That single pass clears up the large majority of connection errors on freshly moved sites.
06. Check the Database Itself in phpMyAdmin
If the credentials are verified, the user is linked, and you still get the error, look at the database contents. It is possible the database exists but is empty, which happens when an import silently failed or the wrong (blank) database was created during setup.
- In cPanel, open phpMyAdmin (Databases section).
- In the left sidebar, click your
DB_NAMEto expand it. - You should see a list of WordPress tables, typically prefixed
wp_:wp_options,wp_posts,wp_users, and so on. - If the database is empty (no tables), the data was never imported. Restore from a backup or re-import your SQL dump, then reload the site.
- If the tables are present, the database is fine and you should move on to the repair and resource-limit sections below.
Our "How to Manage Your Database with phpMyAdmin" guide covers browsing tables and importing a SQL file if you need to bring the data back in.
If wp-config.php points at a database that exists but is empty, WordPress may actually get past the connection error and instead offer to run its install wizard, which would overwrite nothing but also would not show your real site. Do not run the install on top of a live site's config. Fix the config or import your data first.
07. Repair a Corrupted Database
If phpMyAdmin shows the tables but the site still errors, or you see a related message about a table being marked as crashed, a table may be corrupted. WordPress ships with a built-in repair tool, but you have to switch it on in wp-config.php first. Add this line anywhere above the "That's all, stop editing" comment:
define( 'WP_ALLOW_REPAIR', true );
Then visit the repair page directly in your browser (you do not need to be logged in):
https://yourdomain.com/wp-admin/maint/repair.php
- Add the
WP_ALLOW_REPAIRline to wp-config.php and save. - Open
/wp-admin/maint/repair.phpin your browser. - Click Repair Database, or Repair and Optimize Database if you want it to reclaim space as well.
- Let it run through every table and report the results.
- Remove the WP_ALLOW_REPAIR line from wp-config.php and save the file again.
The repair page is deliberately accessible without logging in, so while WP_ALLOW_REPAIR is set to true, anyone who finds the URL can trigger a repair on your database. Delete that line from wp-config.php the moment the repair finishes. Leaving it in place is a real security exposure, not just untidy.
If the built-in tool cannot fix a table, you can repair it manually in phpMyAdmin: open the database, tick the affected table, and choose Repair table from the "With selected" dropdown at the bottom of the table list.
08. One Page Works, Another Fails
Here is the nuance that confuses people: the connection error appears on some pages but not others. If the credentials were wrong, every single page would fail, because they all authenticate the same way. So when the home page loads but a specific post, category, or the admin dashboard throws the error, the connection is fine and one or more individual tables are corrupted.
A crashed wp_options table can break the admin while leaving cached front-end pages working. A damaged wp_posts table might break certain posts. The tell is the same error on a subset of URLs rather than the whole site.
Wrong Credentials
A value in wp-config.php no longer matches the database. Authentication fails, so the connection never opens.
- The error appears on every page, front end and admin alike
- Triggered by migrations, password resets, or typos
- Fixed in cPanel: verify names, reset password, link the user
Corrupted Database
The connection succeeds but a table is damaged, so queries against it fail.
- The error appears on some pages, not all of them
- Often follows an unclean shutdown or a disk-full event
- Fixed with the WordPress repair tool or a phpMyAdmin repair
Match your symptom to the correct column before you start fixing. A site-wide error is a credentials problem; a partial error is a corruption problem. Diagnosing the wrong one wastes time.
09. Resource Limits and Too Many Connections
The credentials can be perfect and the tables healthy, and you can still see the connection error intermittently if the account or the database server is overloaded. Every account on our shared hosting has resource limits (CPU, memory, and concurrent processes), and MySQL/MariaDB will refuse new connections once too many are open at once. When that happens, WordPress cannot get a connection and reports the same error, but only under load, and it clears when traffic drops.
- Intermittent error under traffic usually means you are hitting connection or resource limits, not a config problem.
- A "too many connections" message points at slow queries or a plugin holding connections open. Deactivate recently added plugins to test.
- Frequent 500 errors alongside the database error point at the account tripping its resource caps. See article 128 for how our resource-limit behavior surfaces as 500s.
Our platform enforces plan limits rather than letting one account starve the server, so the answer to persistent overload is to reduce the load (caching, fewer heavy plugins, optimized queries) or move to a plan with more headroom. If you suspect a single runaway query or plugin, disabling plugins one at a time is the fastest way to find it. A repeated critical error on the site can share the same root cause, and our "How to Fix There Has Been a Critical Error on This Website" guide covers reading the debug log to pin it down.
Aggressive object and page caching cuts database load dramatically, which often makes intermittent connection errors disappear on their own. If your site spikes at predictable times, look at what is querying the database on every page load before assuming you need a bigger plan.
10. After a Migration, and When to Open a Ticket
Most connection errors we see arrive within a day of a site move, and they trace back to one of three things. Run this checklist after any migration:
- Credentials updated: wp-config.php uses the new account's
DB_NAME,DB_USER, andDB_PASSWORD, andDB_HOSTislocalhost, not the old host. - Database imported: phpMyAdmin shows the full set of
wp_tables in the new database, not an empty shell. - User linked: the new database user is attached to the new database with all privileges.
If you would like us to handle the move so these are set correctly from the start, our "How to Migrate a WordPress Site to Ultra Web Hosting" guide explains the process and what we take care of for you.
When the problem is clearly not WordPress-specific (any application on the account cannot reach the database, or command-line MySQL fails), you are looking at general database connectivity, and article 176 covers that broader "cannot connect to MariaDB/MySQL database" case.
Open a support ticket when: you have verified the credentials and linked the user but the error persists; you suspect a database server issue on our side (which is rare, but we can check the server logs); or you cannot recover the correct credentials and need help resetting them safely. Include your domain and the exact error text and we can usually pin it down fast.
Still Seeing the Error?
If you have worked through the credentials, the user link, and a repair and the site still will not connect, open a ticket. We can check the database server, review resource usage on your account, and confirm the credentials from our side in a few minutes.
Open a Support TicketQuick Recap: Fixing the Connection Error
If you only do a handful of things from this guide, do these, in order:
- Check the four wp-config.php lines -
DB_NAME,DB_USER,DB_PASSWORD, andDB_HOST- and confirm each against cPanel MySQL Databases. - Make sure DB_HOST is localhost on our shared hosting, not
127.0.0.1or a remote host from the old server. - Reset the database password in cPanel and paste the exact value into
DB_PASSWORDwhen you are unsure. - Confirm the user is attached to the database with all privileges, then check phpMyAdmin shows the tables and not an empty database.
- Repair a corrupted database with
WP_ALLOW_REPAIRand/wp-admin/maint/repair.php, then remove the flag from wp-config.php right after. - Rule out resource limits if the error is intermittent under load, and open a ticket if credentials are correct but it still will not connect.
Last updated July 2026 · Browse all WordPress articles
