Pages

Thursday, September 24, 2009

unable to connect to MySQL Or MySql is not Allowing more Connections

some times aborting connections or interrupting process lead to another problem to server from stop giving connections to client. that is
server do not allow any more connections to client.
probable causes would be.
client is idle more than wait_timeout or
due to long queries getting aborted from client or
client makes mistake in authentications while connecting to database.
all these lead to increase in aborted_client counter of server variable.

and if max_connect_errors= (default is 10) is set to very low will cause a server to give more connection to client when it goes beyond limit
so its better to set it something more (normally 5000-10000) which will minimize this error.

please see more ref. I found for same

http://dev.mysql.com/doc/refman/5.0/en/blocked-host.html
http://dev.mysql.com/doc/refman/5.0/en/communication-errors.html
http://lists.mysql.com/internals/33476

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

I have noticed this error in my MySql Outage, suddenly going down due to overload.
after my observation I found that this kind of error mostly will cause because of
system variables settings of wait_timeout and interactive_timeout on mysql server is set lower than datasource
idle timeout period.
my datasource pooling property for conection time out is set to 1 min
on server variable wait_timeout is set to 28 sec. (28800 milisec)

in most cases where connection is idle from host and if server wait_timeout is less than client datasource timeout
server closes connection after its sleep time is more than wait_timeout or interactive_timeout period. and client is unaware of this
and when he fires query again on same connection gets above error.

to avoid this there are following ways
1. if you are using plain connection using jconnector set autoconnect property to true.
2. if you have custom connection poolilng machanism try to validate your connection before using it from pool.
3. in other case try to set your server variable values for wait_timeout, interactive_timeout greater than your datasource timeout.