Lose MySQL database connection

http://compsci.epizy.com/tutor/index.php

Though I can connect to my database more times, my website generates “Cannot connect to database” error messages about every third request. The same site (index.php) will be able to connect one request and then not be able to connect again, though other requests are not running. It seems the connection fails to be made sometimes and work other times.

I am using php with MySQL and a codebase called Easy!Application. It works locally with every request but on infinityfree , I cannot connect on every request.

Any idea why the database connection seems to be flaky? I am not making more than 50 calls per day, maybe 2 an hour.

The message “Cannot connect to database” is not a message from PHP or the database connection, so it could mean anything. Do you know (or could you record) the exact error message generated by the database connection?

2 Likes

I found the error in the logs. A single request to my site is exceeding max_user_connections, which is set to 9.

Hello,

I was posting same question about MySQL db connection issue week ago or so but not in appropriate topic ( Mysql problem please help me ) . I see this topic might be the correct one so I’m again reporting same MySQL db connection issues that keep appearing from time to time not only in my web application scripts but also in phpMyAdmin!

Inside my custom PHP scripts I’m getting error "SQLSTATE[HY000] [2002] Connection refused”

And in phpMyAdmin when I try to dump whole database into .sql file some interruption happens on MySQL server side making dumping process to stop and downloads incomplete .sql file. Inspecting this incomplete .sql file I can find error saying : #2006 - MySQL server has gone away !

Regarding my case, this MySQL connection error was not appearing before although I’m still using free hosting account for more over than a year.

Can You tell me if this issue is happening on Your side or there is something I should check more and how this issue can be resolved?

Thank You,
Best regards

The connection refused is because of my visitor requests maxing out the number of sql connections I am allowed on the free tier. In other words, over 9 database connections are active in some part of my site due to asynchronous ajax calls.

To work around the issue, I can either reduce the number of connections per visitor, upgrade to the paid version (though the max # of connections is only slightly large), or hope my few visitors do not exhaust the connection by not keeping those ajax pages open. These are my only solutions because we cannot change max_user_connections in mysql configuration.

Thank You for sharing Your experience with similar issue.

Since I’m also still using free hosting subscription, can You tell me in what part of Cpanel You were able to check the logs part that revealed Your errors/issues?

Either way, can’t claim yet but I really don’t think max number of mysql connections were reached on my side at given time to cause stated db connection problem because I was not experiencing this type of issue earlier.

Thank You,
Best regards

I use a framework called CodeIgniter and it collects individual errors from php files. The error message was in the logs applications/storage/logs. In your case, it may be the specific php file (if you are using php) that spits out the error about maximum user connections.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.