Application Cannot Connect to Database

What causes an application cannot connect to database error?

There are several things that could cause an application cannot connect to database error. It means for some reason, the PHP code isn’t able to retrieve information from the database where everything is stored. You may be using the wrong database name, the wrong username/password, the wrong database host or the database may have even become corrupt. This error typically manifests itself by displaying “ERROR  ESTABLISHING DATABASE CONNECTION” when visiting the site in question.


How to fix application cannot connect to database error

If you’re getting the application cannot connect to Database error, try these steps:


  • Make sure you’re adding your MySQL username before the database name (username_databasename)
  • Make sure you’re using the correct database host, if your database is hosted on the same server as the site this will be localhost
  • Make sure you’re using the right database, username and password


If you’ren’t sure if you’re using the right username and password, you can create a fresh username and password using MySQL® Databases in your cPanel. Under “Add New User”, set a username and password and click “Create User”.


Showing where to add users in the Add New User box in MySQL Users


Now you need to assign the new user you just created to the right database. Go to “Add User to Database” to do so.


Showing where to add new users to a MySQL database


Important: You’ll need to change your wp-config file to use the new username and password, too.


How do I 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.


  1. Go to the File Manager in cPanelShowing where to locate File Manager in cPanel
  2. Find your wp-config file.
  3. Add this just above the line that starts with “That’s All, Stop Editing”:
  4. Visit
  5. You should see a page with options to repair or repair and optimize
  6. Visit
  7. You should see a page with options to repair or repair and optimize

Important: This page is not secure and can be accessed by anyone. If you go this route, make sure you remove that line from the wp-config file when you’re done.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Adding a MySQL user to a database

How do I Add a User to a MySQL Database? You can easily add a user to specific MySQL...

Creating a MySQL Database

How do I Setup a MySQL Database in cPanel? Setting up a database for your website can be done...

Creating a MySQL User

How Do I Create A MySQL User In cPanel? To create a MySQL user follow the guide below.  This...

Definition of Databases Icons

The Database section in cPanel allows you to administer every aspect of your MySQL database....

How to Increase the Timeout in PHPMyAdmin

If you have VPS and happen to be running phpMyAdmin then you may have ran into the following: No...