Need help? Chat now!

Hostwinds Tutorials

Search results for:


Table of Contents


Causes for the "application cannot connect to a database" error.
How to fix an "application cannot connect to database" error.
How to repair a corrupt WordPress database

Application Cannot Connect to Database

Tags cPanel 

Causes for the "application cannot connect to a database" error.
How to fix an "application cannot connect to database" error.
How to repair a corrupt WordPress database

Causes for the "application cannot connect to a database" error.

When you receive this error, the PHP code cannot retrieve information from the database where everything is stored.

Several potential causes for this could be:

  • You may be using an incorrect database name
  • Using the wrong username/password
  • Using an incorrect database host
  • The database itself may have even become corrupt.

This error will typically manifest when visiting the site in question by displaying "ERROR ESTABLISHING DATABASE CONNECTION."

How to fix an "application cannot connect to database" error.

If you are getting this database error, you can try these steps to resolve the issue:

  • Make sure you're adding your MySQL username before the database name (username_databasename)
  • Make sure you're using the correct database host. If you host your database on the same server as the site, this will be localhost.
  • Make sure you're using the correct database, username, and password.
  • If you aren't sure if you're using the correct username and password, you can create a new username and password using MySQL® Databases in your cPanel. Under "Add New User," set a username and password and click "Create User."

Once you have done so, you need to assign the new user you just created to the proper database. Go to "Add User to Database" to do so.

Note: You'll need to change your wp-config file to use the new username and password to complete this section correctly.

How to repair a corrupt WordPress database

If you suspect your database may be corrupt, you can try to repair it with the built-in repair function in WordPress.

To do so, start by moving to the File Manager in cPanel and find your wp-config file.

Look for the line that starts with "That's All, Stop Editing" and above it, place this snippet of code:

define('WP_ALLOW_REPAIR', true);

Once you have done so, visit http://www.yourdomain.com/wp-admin/maint/repair.php.

You should see a page with options to repair or repair and optimize. Note: Make sure to make the repair quickly. This page is not secure, and any person can access it at any time. If you do the repair in this way, make sure you remove that line from the wp-config file when you have finished, keeping your site safe.

Written by Hostwinds Team  /  December 13, 2016