Hosting WordPress Spanish version

Support article

Database Connection Error in WordPress

Fix the Error Establishing a Database Connection message by checking wp-config.php, MySQL, credentials, permissions, and possible damage.

Published: 30/06/2026 Updated: 12/07/2026

What this error means

The message “Error establishing a database connection” means WordPress can’t communicate with the MySQL or MariaDB database.

The site’s files may still be there, but WordPress needs the database to fetch posts, pages, users, and settings. When the connection fails, the site and the admin area can become unreachable.

Before modifying files or tables, back up whenever possible (see WordPress backup and restore).

Why it happens

The most common causes are: an incorrect database name, user, or password; a wrong DB_HOST; a user without permissions on the database; a database that was deleted, renamed, or moved; the MySQL service being stopped or overloaded; damaged tables; the server running out of space; an incomplete restore or migration; or a recent change to wp-config.php.

Step 1: check whether the error affects the whole site

Try https://yourdomain.com and https://yourdomain.com/wp-admin. If the same error shows on both, it’s most likely a connection, credentials, or MySQL service issue. If the public site shows the error but /wp-admin says the database needs repairing, a table may be damaged.

It’s also worth checking whether other applications using databases on the same account are failing — if all of them are, the issue may be with the database service itself.

Step 2: check the credentials in wp-config.php

Open wp-config.php, in WordPress’s main folder, and find:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );

Check that there are no extra spaces inside the quotes, that upper/lowercase is correct, that the name includes the prefix assigned by the panel, and that DB_HOST matches the value your hosting provider gives you. On many hosts DB_HOST is localhost, but that shouldn’t be assumed.

Don’t send the full file over email or chat — it contains the database password and other sensitive keys.

Step 3: verify the database and user exist

Access MySQL management from DirectAdmin or cPanel.

In DirectAdmin: open MySQL Management, check that the database in DB_NAME appears in the list, and review which user is associated with it.

In cPanel: open MySQL Databases, check the database and user, and confirm the user has been added to that database with the necessary privileges.

The visible names may include the account prefix (for example account_database) — use the full name.

Step 4: reset the MySQL user’s password

If you can’t confirm the current password, change it from the panel using a long, unique password, update DB_PASSWORD in wp-config.php, save the file, and test the site. Make sure you’re modifying the correct user — one account can have several databases and users.

Step 5: check the privileges

The user needs sufficient permissions on the WordPress database. In cPanel you can usually remove the user from the database and re-add it selecting All Privileges. In DirectAdmin, review the user-database relationship from the MySQL section. Don’t grant global permissions to users that don’t need them.

Step 6: test the connection with phpMyAdmin

Open phpMyAdmin, select the database, and check whether WordPress’s tables show up, such as wp_options, wp_posts, and wp_users (the prefix may not be wp_). If phpMyAdmin won’t open or shows a server error, MySQL or MariaDB may have an issue that needs technical review.

Step 7: check the table prefix

In wp-config.php you’ll find a line like $table_prefix = 'wp_';. Check that it matches the tables’ real prefix. An incorrect prefix doesn’t always show exactly this connection error — it can also make WordPress look like a fresh install or show missing data.

Step 8: repair damaged tables

If WordPress can connect but detects damaged tables, temporarily add this to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Then open https://yourdomain.com/wp-admin/maint/repair.php and choose Repair Database. This page doesn’t require login while the constant is active, so remove the line from wp-config.php as soon as you’re done.

Step 9: check the account’s space and limits

If the server or account runs out of space, MySQL may not be able to write temporary data and WordPress can fail. Check disk usage, the account quota, the database size, log files, and accumulated backups.

Step 10: review a recent migration or restore

After moving the site, confirm you imported the correct database, that wp-config.php has the new server’s credentials, that the user is linked to the database, that the import finished without errors, and that the table prefix is correct. See migrating WordPress to another host if the error appeared after a move.

Step 11: rule out a MySQL server issue

If the credentials are correct and phpMyAdmin can’t connect either, the MySQL or MariaDB service might be stopped, restarting, or overloaded. Contact support with the affected domain, the database name (without the password), the approximate start time, the exact message, and whether phpMyAdmin works.

What not to do

Don’t replace all of WordPress without diagnosing first, don’t delete the database or create another one with the same name without a backup, don’t publish wp-config.php, don’t change DB_HOST at random, and don’t restore an old backup without weighing the recent content you might lose.

Frequently asked questions

Does this error mean the database has been deleted?

No. It’s often caused by an incorrect password, missing permissions, or a temporary service outage.

Why did it appear after changing the MySQL password?

Because WordPress keeps trying to connect with the old value stored in wp-config.php. Update DB_PASSWORD.

Can I create a new user to recover the site?

Yes, as long as you link it to the database and update DB_USER and DB_PASSWORD in wp-config.php.

Can this be caused by too much traffic?

Yes. An overload can exhaust connections or server resources. In that case, check slow queries, caching, plugins, and your plan’s capacity.

Conclusion

The WordPress database connection error is usually resolved by checking the four constants in wp-config.php, and confirming the database, user, and its privileges exist correctly.

If everything is correct and you also can’t access phpMyAdmin, the database service likely needs technical review. Give support the exact message and the checks you’ve already run, but never send passwords in plain text.