Cheapest way to to determine if a MySQL connection is still alive
Posted
by MtnViewMark
on Stack Overflow
See other posts from Stack Overflow
or by MtnViewMark
Published on 2010-03-30T16:31:12Z
Indexed on
2010/03/30
16:33 UTC
Read the original article
Hit count: 325
I have a pool of MySQL connections for a web-based data service. When it starts to service a request, it takes a connection from the pool to use. The problem is that if there has been a significant pause since that particular connection has been used, the server may have timed it out and closed its end. I'd like to be able to detect this in the pool management code.
The trick is this: The environment in which I'm coding gives me only a very abstact API into the connection. I can basically only execute SQL statements. I don't have access to the actual socket or direct access to the MySQL client API.
So, the question is: What is the cheapest MySQL statement I can execute on the connection to determine if it is working. For example SELECT 1;
should work, but I'm wondering if there is something even cheaper? Perhaps something that doesn't even got across the wire, but is handled in the MySQL client lib and effectively answers the same question?
© Stack Overflow or respective owner