How to Fix “Error Establishing a Database Connection”
WordPress can't connect to its database. Check that the database name and username in wp-config.php match the Databases section of cPanel, ask us to check the database login if they do, and check the status page.
Applies to: cPanel WordPress Blue Arctic Shared Web Hosting (cPanel); WordPress 7.x
On this page
WordPress keeps your posts, pages and settings in a database. This message means WordPress couldn’t log in to it, so nothing can load. The usual causes are a changed password, a wrong detail after a move, or the database service being briefly unavailable.
If the error comes and goes by itself, your database details are almost certainly right. Skip Step 2: check the status page, then open a support ticket and tell us when you saw the error.
Note
These steps use cPanel on Shared Web Hosting. If you have Managed WordPress Hosting, open a support ticket instead. If you can’t find a cPanel tool named below, type its name in cPanel’s search box (Ctrl+K or Cmd+K). If you can’t log in to cPanel or still can’t find it, open a support ticket.
Step 1: Check whether it’s a wider problem
- Open the Blue Arctic status page. If it shows an incident, wait for the update.
- If you have more than one WordPress site, check whether they all show the error. If they all do, open a support ticket.
Step 2: Compare wp-config.php with cPanel
- Log in to cPanel, click Files in the sidebar and open the File Manager tab. If you see a File Manager icon instead, click it.
- Open
public_html(or the folder for this site). - Select
wp-config.phpand choose Edit from the More (⋮) menu. You’re only reading it, so don’t change anything. - Find the lines for
DB_NAME,DB_USERandDB_HOST. Each value is in the second pair of quotes. For example, indefine( 'DB_NAME', 'example_wp123' );the database name isexample_wp123. Write the three values down, then close the file without saving. - In cPanel, click Databases in the sidebar and check that a database with exactly the
DB_NAMEname is listed. - Click Manage next to it, open the Users tab and check that the
DB_USERname is listed.
If you see a Manage My Databases icon instead, click it and check under Current Databases that DB_USER is listed under Privileged Users for that database.
Names must match letter for letter, exactly as cPanel shows them.
If the user isn’t listed for that database, or the database or user isn’t in cPanel at all, don’t add or create anything. If you moved this site here yourself, go to “After moving the site” under Troubleshooting. Otherwise, open a support ticket with both names (never the password).
Leave DB_HOST as it is. If you moved the site from another host and DB_HOST isn’t localhost, open a support ticket before changing it.
Step 3: Ask us to check the database login
If the names match, the password is the most likely cause.
- Open a support ticket and ask us to check the database login for your site. Include your site address and the
DB_NAMEandDB_USERnames. Never put a password in the ticket. - If other applications use this database user, mention them.
Step 4: If the message changes to “tables are unavailable”
If WordPress says “One or more database tables are unavailable. The database may need to be repaired.”, a table may be damaged. Don’t try to repair it yourself: a repair can lose data in rare cases. Open a support ticket with the exact message and ask us to check the database. We keep daily backups for 30 days.
How to tell it worked
Your site and its admin area load normally in a private browser window.
Troubleshooting
- The error started with no change on your side: check the status page, then open a support ticket. Someone may also have changed the password. If you suspect a break-in, say so in the ticket right away.
- After moving the site: if we moved it for you, open a support ticket and we’ll look at it. If you moved it yourself,
wp-config.phpmay still hold the old host’s database details. You can update it yourself only if all four of these are true. If not, open a support ticket.- You created the database on this account, and you imported your old site’s database into it.
- You saved its name, username and password.
- The password has no quote mark (
') or backslash (\) in it. Those can break the file. - The
DB_HOSTvalue you wrote down in Step 2 islocalhost.
wp-config.phptakes the site offline, so save a copy first (step 1).- In File Manager, select
wp-config.phpand click Download to save a copy on your computer. - With the file still selected, choose Edit from the More menu.
- Find the
DB_NAME,DB_USERandDB_PASSWORDlines. On each, replace only the value in the second pair of quotes. Use the full database name and username exactly as cPanel shows them under Databases, and the password you saved. Keep the quotes. - Save the file and reload your site.
- If you see a blank page or a different error, put your copy back. In the same folder, click Upload, select Overwrite existing files and choose the copy from step 1. It must still be named
wp-config.php. - If you see a WordPress setup screen (it asks for a language or a site title), don’t fill it in. The database is empty.
- In either case, or if the same error is still there, open a support ticket and tell us you edited
wp-config.php.
- The database is missing from the list: don’t create a new empty one. Open a support ticket and ask about restoring it from a backup.
Still need help?
Open a support ticket from the Client Portal at my.bluearctic.com. Include your site address, when the error started, whether you changed anything, the database name, and what you already tried. Never include a password.