0 items
24/7 Support & Sales   1300 210 210
Online Support Web Hosting

Database connection error with WordPress

A database connection error means that a program or widget running on your site is not able to communicate with a MySQL database. Due to this, the program you are trying to run or use will be unable to execute commands or perform tasks.

This type of connection error will most often be displayed as a notification, which could be seen below:

Error establishing a database connection.

Possible Causes behind database connection errors

There are several possible reasons why you may be getting a database connection error. Below are some of the most common ones:

  • Wrong login credentials – you may have the wrong username and password
  • Database errors – your database may have corrupted data or your MySQL is not active.
  • Server issues – your hosting may be down or having problems. For this, it is best that you contact our 24/7 technical support.

Important Note: Before doing anything to try and resolve your database connection issues, it is highly recommended that you back up your files first.

If you want to know how to get backups of your website files, click the links below:

To check out what the problem is and try to resolve the issues, run the following tests.

Check Configuration Settings

The database username and/or password you are using may not match the configuration settings stored in the server. If this is the case, you should make sure the configuration settings match by checking them in the Hosting Manager. It is recommended that you check your configuration settings in both MySQL Databases and File Manager features.

If you’re not certain that you remember the current password, it is best that you change the user password.

MySQL Databases

To check the database configuration files, follow the steps below:

  1. Click on My Account at the top of the page.
  2. Select Hosting Manager from the drop-down menu.
  3. Enter your username and password, and click Log In.
  4. On the Home page, click the word Databases or the [ v ] arrow symbol on the right side.
  5. Click the MySQL Databases button, which is next to phpMyAdmin icon.
  6. Under Current Users, check the username connected to the database your program is trying to access.
  7. After confirming the database name and username, if you can’t remember the password, you may reset it and create a new one. To do this, click Change Password or the key symbol to the right to change the password.
  8. On the next page, below the Set MySQL User Password, fill out the Password fields.
  9. Click Change Password to save your new password.
    You will then get the following notification:
  10. You have successfully set this user’s password.
  11. Click OK to go back to the MySQL Databases main page.
    If you find it difficult to make a strong enough password for your email, you can let the system create one for you.
    Click the Password Generator button. In the pop-up box, copy the generated password and paste that in the Password fields.
    You can also choose to check I have copied this password in a safe place. Then, click Use Password. This will automatically copy and paste the generated password in the Password fields.

    Important Note: Make sure you have actually saved the generated password in a safe and easy to recall place.

Congratulations, you now know how to check your database configuration settings and reset your password.

File Manager

You should also check the configuration settings in your wp-config.php file in your File Manager. To know how to access your File Manager, click the link below:

Once inside the File Manager, follow the steps below:

  1. Go to your public_html folder and look for the wp-config.php file.
  2. Right-click on the file, and then click Edit.
  3. In the pop-up window, click Edit. This will open the file on a text editor.
  4. Check the following lines and see if you have the correct database details:
        Define('DB_NAME', 'database-name'); 
        Define('DB_USER', 'database-username');
        Define('DB_PASSWORD', 'database-password');
        Define('DB_HOST', 'localhost');

You may also try repairing the database through WordPress. To do this, follow the steps below:

  1. Go to your public_html folder and look for the wp-config.php file.
  2. Right-click on the file, and then click Edit.
  3. In the pop-up window, click Edit. This will open the file on a text editor.
  4. At the bottom of the file, add the following line of code:
    define( 'WP_ALLOW_REPAIR', true );
  5. Next, open a web browser tab and paste the following url in the browser address:
    www.yourdomain.com/wp-admin/maint/repair.php
  6. Note: Make sure to replace “yourdomain” with your own domain name.

  7. The page will then display options for you to repair and/or optimize your database. Click Repair Database or Repair and Optimize Database to repair and/or optimize your database.
  WordPress Database Repair feature

Important Note: After the task is complete, it is highly recommended that you remove the line you previously added in your wp-config.php file. This is to prevent the page from being used by unauthorised users.

Check if MySQL is active

Another possibility that you are unable to establish a connection to the database is if it is deactivated. To check if your database is active or not, you can use the following:

  • phpinfo.php file
  • Telnet

With phpinfo.php page

To access the phpinfo.php, follow the steps below:

  1. Open a web browser tab.
  2. Type the file's web address (url) in the browser address bar. Usually, the file can be found in the public_html/www directory. The URL will be http://yourdomain.com/phpinfo.php. Simply replace the “yourdomain.com” with your own domain name.
  3. If you typed in the correct path, the page should load and display all information about the configuration of your server. To get the information on MySQL, simply scroll down to get to the MySQL data tables.
    By default, the tables will be arranged in alphabetical order.

If you don’t have a phpinfo.php page yet, you can create one in your File Manager. To know how to create a phpinfo.php file, click the link below:

With Telnet

To use Telnet to check if your MySQL database is activated, follow the steps below:

  1. With your Windows computer, access the Start menu.
  2. Next, go to Run, then type cmd to access command prompt.
    If you are using Mac, go to Search on the upper right corner of your screen, and type "terminal". Click on the top search result and that should launch the terminal window on your Mac.
  3. Once inside the command line interface or terminal window, type the following command:
    telnet yourdomain.com 3306
    Be sure to replace the "yourdomain.com" with your own domain name.
  4. Hit the Enter key on your keyboard. This will activate the command, test the port, and your computer will try to connect to your server through Telnet.
    If your MySQL database is activated, you will get a confirmation string that will start with a MySQL database version number.
    If your MySQL database is deactivated, you will receive the error message Could not open connection to the host.

Note: There is also the possibility that the likely causes of service unavailability are either a temporary high load on the server, or the service is being restarted. This should clear up within minutes.

Check your database

Yet another reason you may be having database connection errors is because some files or sections may be corrupted. To find out if this is the case, you need to run a system check on your database. To do this, follow the steps below:

  1. Click on My Account at the top of the page.
  2. Select Hosting Manager from the drop-down menu.
  3. Enter your username and password, and click Log In.
  4. On the Home page, click the word Databases or the [ v ] arrow symbol on the right side.
  5. Click the MySQL Databases button, which is next to phpMyAdmin icon.
  6. Under Modify Databases, go to Check Database. Select the database you want to check, then click the Check Database button to the right.
  7. The system will then run a script to check the database.
    If the system detects an error, it will say so in the results page and will even specify where the corrupted files or sections can be found.
    If the database has no problems, it will display a gray box with a list of sections with “OK” statuses and the phrase Check Complete in a green box at the bottom.

If the database check returned some errors, you can try to resolve these by running “Repair Database”. To know how to do this, click the link below.

If you have a backup copy of your MySQL database, you may also restore your database to a previous version. To know how to do this, click the link below:

If you are still unable to resolve the issue after a time, please contact our 24/7 technical support.

If you want to know how to install WordPress on your Web Hosting, click here.

If you want to know how to install WordPress with FTP, click here.

Was this helpful? Yes No 55% of people found this helpful.