A Web.com Partner
Sign Up / Log In
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.

In this article, we’ll help you understand the different causes behind database connection errors. Also, we’ll give you insights on how to resolve this issue by:

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: Before doing anything to try and resolve your database connection issues, it is highly recommended that you backup 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 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. Access your MySQL Database.
  2. Under Current Users, check the username connected to the database your program is trying to access.
  3. 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.
  4. On the next page, below the Set MySQL User Password, fill out the Password field.
  5. Click Change Password to save your new password.
    You will then get the following notification:
    You have successfully set this user’s password.

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: 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


Follow the steps below to check the configuration settings in your wp-config.php file in your File Manager.

  1. Access your File Manager.
  2. Scroll to your public_html folder and look for the wp-config.php file.
  3. Right-click on the file, and then click Edit.
  4. In the pop-up window, click Edit. This will open the file on a text editor.
  5. 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. Access your File Manager.
  2. Scroll to your public_html folder and look for the wp-config.php file.
  3. Right-click on the file, and then click Edit.
  4. In the pop-up window, click Edit. This will open the file on a text editor.
  5. At the bottom of the file, add the following line of code:
    define( 'WP_ALLOW_REPAIR', true );
  6. Next, open a web browser tab and paste the following url in the browser address:
    www.yourdomain.com/wp-admin/maint/repair.php

    Note: Make sure to replace “yourdomain” with your own domain name.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: 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. Access your MySQL Database.
  2. Under Modify Databases, go to Check Database. Select the database you want to check, then click the Check Database button to the right.
  3. 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 us for further assistance. We’d love to help!

Was this helpful? Yes No 54% of people found this helpful.
{"message":""}