Troubleshooting a Database connection error

Getting a database connection error, such as this one in Joomla, 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 check 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. If you are unsure where these files are located for your program, you can check to see if the program is listed in our configuration files list article. 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.

Note that newer versions of Windows do not have the Telnet service enabled by default. You may have to enable it before running this test. You can find instructions on how to do this in our article on enabling telnet on a Windows computer.
  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 Live Support team for further assistance.

23 thoughts on “Troubleshooting a Database connection error

  1. For Windows 10 telnet is not installed by default. You need to do the following for it to work: 

    1. Open “Control Panel“.
    2. Open “Programs“.
    3. Select the “Turn Windows features on or off ” option.
    4. Check the “Telnet Client” box.
    5. Click “OK“. A box will appear that says “Windows features” and “Searching for required files“.When complete, the Telnet client should be installed in Windows.
  2. I am getting the error: “Failed to connect to the database” – tried the the Telnet Test and I am getting the following message:

    Mac-0026b0ef185e:~ w16141$ telnet strategicanalytics-cip.com 3306

    Trying 173.247.252.218…

    Connected to strategicanalytics-cip.com.

    Escape character is ‘^]’.

    N

    5.6.21-logb;MN#bDm?7F:1&fTPtvvmmysql_native_passwordConnection closed by foreign host.

    Any help will be appreciated!

     

    Carlos

  3. Hi Scott,

    Actually only my main page https://www.catalogue.com.sg shows the error message.

    My other pages are fine.

    Why is this so?

    Can you help me look into the issue please.

    Thanks

    Belle

    1. Hello Belle,

      It appears the site just needed the time to get rid of the cloudproxy cache and propagation to the server itself. I am showing your site quite fine now and am not getting any errors.

      Kindest Regards,
      Scott M

    2. I have been having a ton of connection errors (too many connections, can’t fetch mysqli, and others) and they can’t seemed to be fixed. I am told it is an OpenCart problem but I couldn’t connect to my WordPress site last night on the same server. Why is that? I did the Telnet yesterday and could not connect to my site. Plus when I have made changes and refreshed my site, the site doesn’t load the colors/template properly at times.

      They just changed my PHP version to the previous one. Now today I can’t add pictures that are already uploaded or make any changes at all and keep getting all those connection errors.

      What can be done? I am at a loss. I need to have this resolved or I can’t launch my website.

      Thanks,
      Diana

    3. Hello Diana,

      Generally the problem comes from software opening connections to mysql and not closing them in a timely manner. The reason your wordpress website was not working was most likely due to your account using all of the allotted mysql space each account is allowed. What is your domain so we may try to troubleshoot further.

      Best Regards,
      TJ Edens

    4. www.christiancoverings.com

      I have found out from support that the max user connects is set to 30.
      Also doing some research on OpenCart forum shows it is a server problem and not an OpenCart problem. I have read it should be: max_connections = 1000
      max_user_connections=200
      (this is a system wide mysql variable)
      Most are 500/100.

    5. Hello Dm5400,

      Setting max connections to 1000 doesn’t solve the issue of why several hundred connections to the database are required by OpenCart. If you want to make that change, it would be better suited to using the installation in a VPS or Dedicated server environment where resources can be more focused to the application. Making these type of changes in a shared server environment can lead to problems with resource usage. If you have a plugin that is requiring that many open database connections, it should not be recommended for shared server use. Also, if you consider that database connections are usually made in conjunction with the number of users in the applications, having several hundred open at the same time should only be made if you have that many concurrent users in the application. If you’re seeing that kind of traffic, then you should definitely not be on a shared server.

      Database connections are not typically held open. They are opened, then shut as soon as a query or update is made. Requiring many concurrent database openings for minimal application use is indicative of an issue that the developer should correct. In the case of OpenCart, I would recommend you review your plugins/extensions. Our web design team uses it for many of our clients, and the max connections setting is never an issue.

      Regards,
      Arnel C.

    6. I am new to OpenCart. The only extension I have is a total based shipping extension by clearthinking. I am using the Journal responsive theme made for OpenCart (modified to suit my simple design). That is it. I do not have a large store nor do I have a lot of traffic to my site. I have always been on a shared server and never had any issues with my site. I have been in contact with the theme support and according to them, it would not cause these issues. I have been able to work on my site the past two days without any error messages, etc. so it’s not everyday I see them.

  4. Hi Arnel and Scott,

     

    Thanks for responding to me.

    I have spoken to 3 of your staff and they all say different things…

    1) Host server is down.

    2) Host server is not down but my Cloudproxy settings are causing the problem.

    Could a technician please help me look into the issue and let me know please..

     

    Thanks in advance

    Belle

    1. Hello Belle,

      The MySQL service issue was fixed on the server, so that should no longer be a factor. The tempURL seems to work and if the domain has been pointed to us recently, then it could still be showing cached information from the CDN. This may take some time to propagate out.

      Kindest Regards,
      Scott M

  5. Hi this 

    Error establishing a database connection

     

    Seems to be happend a couple of times and the chat staff said your server is down..

     

    Can please help to resolve asap.

     

    Thanks

    1. Hello Belle,

      Sorry for the database issues. If the server was reported down, then the database connection would not work. However, as per the support ticket in your account, it does look as they have fixed the issue for you. If you continue to have any further problems, please let us know.

      Regards,
      Arnel C.

    2. Hello Belle,

      You are on a server that is currently having MYSQL service issues. Our Systems team is working hard to get that back up as quickly as possible for you.

      Kindest Regards,
      Scott M

Was this article helpful? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X