Database connection errors are one of the more common errors seen on a website. They also seem to cause a bit of panic. When you receive this error message, it means that the program is not communicating properly with the MySQL database service on the hosting server. This article will help you determine if the issue is your hosting server itself, or if you need to check the configuration settings for the connecting program.
We want to do a test known as the TelNet test. This allows us to test the server without going through the program that was giving the error. This way, we can tell if the MySQL database service is running on the server. Telnet is a network protocol that you will use to connect to the server directly.
- From a windows machine, access the command line from start -> run -> cmd. If you are using a Mac, open up the Terminal application.
Telnet is disabled by default on newer versions of Windows. If it is disabled on your version, you will receive a message stating something similar to 'telnet' is not recognized as an internal or external command, operable program or batch file.
You can enable telnet by following the instructions in our article named How to enable Telnet on Windows machines
- From inside the command prompt, type the command telnet <domain name> 3306. Telnet is the command to open the telnet protocol, the domain name is the name of the domain you want to contact, and 3306 is the specific port for MySQL for Web Hosting Hub. Be sure to replace <domain name> with your actual domain name. You can see an example of how it should appear below.
telnet example.com 3306
- Hit enter to activate the command. If the MySQL service is running, you will receive a response from the server. Although it appears cryptic, it is a confirmation beginning with the MySQL version number. If MySQL is not available on your server at the moment, you will receive a connection error.
MySQL Service available
MySQL service unavailalbe
Connecting to example.com...Could not open connection to the host, on port 3306: Connect failed.
Check Program configuration files
If you get the response that indicates the MySQL service is indeed up and running, the next thing to check is whether the credentials the program is using match the server. You will need to know the database name, username, and password the server is expecting and the database name, username, and password the program is using to try and make the connection.
To find the credentials the program is using, look for the database settings found in your program files. If you are unsure where to find the database connection credentials for your program, you can check our configuration file location list for your particular program. Be sure you write down the location of the file and the database credentials you find.
After finding the credentials in the program, you want to see if they match the ones in the cPanel. To find the database information in the cPanel just follow these steps:
- Log into your cPanel account.
- Find the Databases category. Click on the MySQL Databases icon.
- Once in the Databases page, scroll down and find your database in the list. You will also see the database user name next to it.
- Once you have confirmed the database and username, you will need to confirm the password. As there is no way to see the password, you will need to first delete, then re-create and attach the database user to the database with the password.
After ensuring the credentials are the same between the server and the configuration file, test your website again. If you are still receiving the database connection error, you will want to contact our Live Support team for further assistance.