How to check a connection to MySQL db is not dead, and avoid unnecessarily (close and) re-create connection? Say, I am creating and using the connection in a Bash script.
Edit
By “dead” i mean, perhaps the last time when a created connection was used is 1 hr ago, and on the server side, perhaps it does something to kill off inactive connections in some way.
The only way to check is to try to use it.
You could pre-emptively execute a basic command like
SELECT 1before executing your real command.