I get Database connection error

September 11, 2017     0 comments

Getting a database connection error can be a scary thing to see on your website. It means that a program running on your site is not able to communicate with the MySQL database service to retrieve data. There are two main reasons for getting this error, either the program itself is not connecting properly due to login credentials mismatch from the program's configuration files, or the MySQL service is currently not running on the server. Below are instructions on how to check both.

Checking Program Configuration Files

If you have recently installed your program or changed the configuration options in the program, you will want to recheck to ensure the configuration files match what the database is expecting. The credentials you will need to know are the database name, host, database user name, and the database password.

First you will want to find these credentials in your program's configuration files. Be sure to write down all the database credentials you find as you will need to check them against the server.

Once you have the credentials from the connecting program, you will need to check them against the server to make sure they are the same. The steps below will guide you on doing that.

  1. Log into your cPanel
  2. Locate the Databases category and click on the MySQL Databases icon.
  3. From the databases page you will see your databases in a list along with the database user in the column next to it.
  4. After confirming the database name and username, you will want to confirm the password. Since you cannot see the password, you will need to reset it by deleting the user and then recreating and attaching it to the database using the password from the configuration file.

Telnet Test

If you have confirmed the credentials and are still getting the error, or the program was working and the database connection error suddenly began, it is possible the MySQL service is not running on the server at the moment. You can test this by running a test with something called Telnet. Telnet is a network protocol that you can use to connect to the server directly and check the service availability. Below are the steps to running a test with Telnet.

  1. Log into your command line interface. With a Windows machine you go to Start -> Run -> cmd. With Mac, you will need to open your Terminal application.
  2. Once in the command line interface, you will type the command telnet example.com 3306. (be sure to replace example.com with your own domain name). Here is the breakdown of the command: telnet is the command to tell the computer to use the telnet protocol. The domain name is telling which domain name/server to connect to, and the 3306 is the port for the MySQL service it will test. Below is an example of how your command should appear.

    telnet example.com 3306

  3. Hit the enter key to activate the command. It will connect to the server using Telnet and test the port. If it is running, you will get a confirmation string beginning with the MySQL database version number.

    5.1.66-c115btB+Q...

    If the MySQL service is not running, you will receive an error as below:

    Connecting to example.com...Could not open connection to the host, on port 3306: Connect failed.

If you receive the connection failed error, the likely causes of service unavailability are either a temporary high load on the server, or the service is being restarted by the Systems Administration team. This should clear up within a few minutes. If you receive the connection confirmation and are still receiving the error, you will want to contact our support team for further assistance.


How helpful was this article to you?

Leave a comment

Your name
Your email address
Comment on this article