Error establishing a database connection in WordPress
Understand and fix the "Error establishing a database connection" message that stops your WordPress site from loading.
·4 min read
"Error establishing a database connection" means WordPress cannot reach its MySQL database. In most cases, a value in the wp-config.php file is wrong: database name, username, password or host. Compare these values with the Databases tool of your hosting, correct them, then reload your site.
Is your site showing a blank page with the sentence "Error establishing a database connection"? Your content is not lost. It is still in the database, but WordPress can no longer connect to it. This guide helps you find the cause and fix it, even without deep technical knowledge.
Why does this error appear?
WordPress stores its text, pages and settings in a MySQL database. On every visit, it connects to it using the details written in the wp-config.php file. If one of them no longer matches, the connection fails and the site cannot display anything.
The most common causes are:
- wrong credentials in
wp-config.php, often after a migration or a manual edit; - a database that was deleted or renamed;
- a database user password that was changed without updating
wp-config.php; - corrupted tables after an interruption during an update;
- a temporarily overloaded database server, which is rarer.
Before you start
- Check whether the error affects the whole site or only the admin area (
/wp-admin). If only the admin is affected, the tables may be damaged (see below). - If you just edited a file, installed a plugin or migrated the site, write it down: it is often the lead.
- A backup of your hosting may already exist, see Restore a backup of your website.
Fix the error step by step
- Open your hosting, then Databases, and find your site's database and its user.
- Open the Files tool and go to the
httpdocsfolder. - Open the
wp-config.phpfile for editing. - Compare the value of
DB_NAMEwith the exact database name. - Compare the value of
DB_USERwith the exact username. - Check the value of
DB_PASSWORD: it is the database user's password, not your WordPress password. - Keep the original
DB_HOSTvalue unless support tells you otherwise. - Save the file, then reload your site.
The lines to check look like this:
define( 'DB_NAME', 'database_name' );define( 'DB_USER', 'username' );define( 'DB_PASSWORD', 'password' );define( 'DB_HOST', 'host' );
Watch the details: a capital letter, a space before or after the value, or a missing quote is enough to break the connection. Keep the straight single quotes around each value.
How do you check that the password is right?
Open the database in phpMyAdmin from the Databases tool, see Create a MySQL database. If you see the WordPress tables (they often start with wp_), the database exists and holds your site. If you no longer know the user's password, open a support ticket: support will help you reset it, and you then copy it into wp-config.php.
What if the admin says "One or more database tables are unavailable"?
The tables are damaged. WordPress has a built-in repair tool:
- Add the line
define( 'WP_ALLOW_REPAIR', true );towp-config.php, just above the line "That's all, stop editing!". - Go to
yourdomain.com/wp-admin/maint/repair.php. - Click Repair Database.
- When the repair is done, remove the line you added: otherwise anyone could run this tool.
What if nothing works?
- Check your hosting error logs (Logs, then Error logs): they often show the exact message returned by MySQL, such as "Access denied".
- Restore a backup taken before the error appeared, see Restore a backup of your website.
- Open a ticket from
/submitticket.phpor email support@upkyo.com, mentioning what you changed recently. Support answers 24/7.
How do you stop the error from coming back?
- Store the database details in a password manager as soon as you create it.
- Never delete a database without checking which site uses it.
- Run updates on a backed-up site, see Update WordPress, plugins and themes.
- When migrating, update
wp-config.phpwith the new hosting details.
Frequently asked questions
Have I lost my website content?
Almost never. The error means WordPress cannot reach the database, not that the database is empty. Once the connection details are fixed, the site comes back exactly as it was.
Where is the wp-config.php file?
At the root of your WordPress installation, usually directly in the httpdocs folder. You can open it with the Files tool in the client area or over SFTP, see Connect with FTP or SFTP.
Is the database password the same as my WordPress password?
No. DB_PASSWORD is the password of the database's MySQL user. Your WordPress administrator password is different and plays no part here.
Why did the error appear after a migration?
The new hosting uses a different database, user or password from the old one. The copied wp-config.php file still holds the old values: replace them with the new ones.
The error comes and goes, is that normal?
An intermittent error can come from a traffic spike or a plugin opening too many connections. Note when it happens and open a ticket: support can check the server logs.