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.
To check the database configuration files, follow the steps below.
- Access your MySQL Database.
Under Current Users, check the username connected to the database your program is trying to access.
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.
On the next page, below the Set MySQL User Password, fill out the Password field.
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.
Follow the steps below to check the configuration settings in your wp-config.php file in your File Manager.
Access your File Manager.
Scroll to your public_html folder and look for the wp-config.php file.
Right-click on the file, and then click Edit.
In the pop-up window, click Edit. This will open the file on a text editor.
Check the following lines and see if you have the correct database details:
You may also try repairing the database through WordPress. To do this, follow the steps below.
- Access your File Manager.
- Scroll to your public_html folder and look for the wp-config.php file.
- Right-click on the file, and then click Edit.
- In the pop-up window, click Edit. This will open the file on a text editor.
- At the bottom of the file, add the following line of code:
define( 'WP_ALLOW_REPAIR', true );
- Next, open a web browser tab and paste the following url in the browser address:
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.
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:
With phpinfo.php Page
To access the phpinfo.php, follow the steps below.
- Open a web browser tab.
- 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.
- 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:
To use Telnet to check if your MySQL database is activated, follow the steps below:
- With your Windows computer, access the Start menu.
- 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.
- 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.
- 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.
- Access your MySQL Database.
- Under Modify Databases, go to Check Database. Select the database you want to check, then click the Check Database button to the right.
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!