Cheapest way to to determine if a MySQL connection is still alive

前端 未结 3 1556
天命终不由人
天命终不由人 2020-12-14 20:48

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 ther

3条回答
  •  孤城傲影
    2020-12-14 21:31

    "Connection" in this case has multiple meanings. MySQL listens on a socket- that's the network-level "connection." MySQL maintains "database connections," which include a context for query execution and other overhead.

    If you just want to know if the service is listening, you should be able to execute a network-level call to see if the port (don't know what the default is) is listening on the target IP. If you want to get the MySQL engine to respond, I think your SELECT 1 idea is good- it doesn't actually fetch any data from the database but does confirm that the engine is spun up and responding.

提交回复
热议问题