WordPress errors

How to fix a WordPress database connection error

A WordPress database connection error means the site cannot reach the database it needs to load its content and settings. Start with the hosting service, then compare the connection details. Creating an empty database or reinstalling WordPress does not bring the existing content back.

Time: 20-45 minutes for the initial checks Level: Hosting access required
Neil McNaught, founder of BugShield and WordPress author
Written by
Written by
Updated
Updated

What a database connection failure means

WordPress stores your pages, settings and other site records in a database separate from its program files. When the connection fails, it cannot read those records to build the page. The message alone does not establish that the data has been lost. Start by checking the hosting service and recent changes, then verify the connection details with a recovery copy available.

phpMyAdmin showing a selected WordPress database and its list of tables
The selected database and its tables are visible in this unchanged Learn WordPress example. Match the database name to the site's configuration during the checks below. Being able to view it in phpMyAdmin does not establish that WordPress has the correct connection details; do not edit or delete tables to test the connection. Credit: WordPress Training Team / Learn WordPress, CC BY-SA 4.0.

Check whether the database service is available

Record the exact error, affected address and time. Open the homepage and your normal dashboard address once. If the error comes and goes, record that too. Repeated refreshes will not correct the connection details and add requests while the service is struggling.

Sign in to the hosting account and check its service-status page and the site's storage quota. Ask support whether the database server is running, whether the account has reached a resource limit, and whether they can connect using this site's configured database user. If a service outage or quota is confirmed, follow the host's recovery instructions before changing WordPress.

Preserve the site's current files and request a database snapshot from the host. If exports still work, follow our manual backup guide. Do not delete tables or replace the database while investigating.

Compare the connection details after a move or password change

This check is particularly relevant if the problem began after a migration or database-password change. Open the affected site's directory in hosting File Manager, identified by its wp-admin and wp-content folders. Locate wp-config.php there or one directory above. Download a secure private copy before opening its text editor.

Find the four settings below and compare them with the database assigned to this website in your hosting panel. They are separate from your WordPress administrator login. Keep their values private; you do not need to send a screenshot of the whole file.

  • DB_NAME: the existing database containing this site's tables, including any hosting-account prefix.
  • DB_USER: the database account assigned to that database, not your WordPress username.
  • DB_PASSWORD: that database user's current password. A hosting panel can reset it but does not necessarily display the existing value.
  • DB_HOST: the database server address supplied by the host. Do not replace it with localhost unless the host confirms that value for this installation.

Correct only a confirmed mismatch

  1. Ask the host to confirm the correct database and user before changing either. In cPanel, Databases > Manage My Databases lists databases and assigned users; older panels call it MySQL Databases.
  2. If a name or host value differs, replace only the text inside its existing quotes in wp-config.php. Keep the setting name, quote marks and ending punctuation intact. Save and test the homepage once.
  3. If the database password must be reset, first confirm whether other sites use that same database user. Arrange a coordinated change with support so those sites are updated too. Have the host update the configuration if the password includes characters you cannot safely represent in PHP.
  4. When the details match but access is denied, ask support to verify that the configured user is assigned to the intended database with the required permissions. Do not create a second empty database as a substitute.

Save a changed password in the configuration

After resetting the database user's password in hosting, update this site's DB_PASSWORD definition to the same new password, save the file and test the homepage. The host can handle this edit if the password requires PHP escaping. Update every other installation using that database account as part of the same change.

If an edit produces a new syntax or critical error, restore the private configuration copy immediately and have the host correct the edit. A restored file with the old password still needs the new database password before it can connect. Our configuration file guide explains where these settings belong.

Handle a damaged or missing database separately

A connection failure alone does not establish corruption. Ask for the exact database error. If the host identifies damaged tables, have them preserve a snapshot and choose a repair appropriate to the database engine. A repair command is not interchangeable with restoring missing data.

For a missing database or an incomplete migration, recover the correct export or backup using the restore guide. On a shop, account for orders and payments created after the backup before replacing data. If the site works between failures, ask the host to investigate connection limits and server health rather than repeatedly resetting the password.

Verify both reading and saving

Load the homepage and several inner pages in a private window, then sign in to the dashboard. Create and save a test draft to confirm the site can write as well as read data. Check recent content and orders against what you expect. Delete the test draft after the check.

If cached pages load while the dashboard still fails, the database problem is not resolved. Follow up with the host using the latest failure time. Once recovery is confirmed, keep the working connection details in secure storage and remove any public copies of configuration backups.

Reference material

See the WordPress database connection guidance and cPanel's Manage My Databases documentation. Your provider confirms the actual host address and account permissions.

Get help with the next step

If the connection details are unclear or the database contains live orders, ask BugShield for help with the database error. Share the error text and recent changes, keeping credentials out of the initial message. We can assess the recovery and confirm a price.

Questions answered

How to fix a WordPress database connection error FAQs

Has the error deleted my pages?

The message says WordPress cannot connect to its database. It does not establish that content has been deleted. Confirm the database exists and preserve it before attempting any repair or restore.

Is the database password my WordPress login password?

No. WordPress uses a separate database account through wp-config.php. Changing your administrator password does not repair that connection.

Why does the error disappear after a refresh?

An intermittent failure needs hosting investigation into service health, connection limits and resource use. Record the failure times. A permanently wrong password would not explain successful connections with the same configuration.

Should I enable WordPress database repair?

Only after a specific damaged-table diagnosis and a preserved backup. Ask your host to select the appropriate repair. Connection failures caused by credentials or a stopped service need different action.

Why can visitors see the homepage while I cannot sign in?

A cache can serve a previously saved homepage without completing the failing database request. Test the dashboard and saving a draft before declaring the connection restored.

Need a hand with your WordPress site?

Tell us what happened and where you got stuck. A BugShield developer can help you work out the next step and confirm a price for the fix.

Explore help with this issue

Accessibility settings

Adjust how this site looks and moves. Your choices are saved in this browser.