It's not unusual for a language that interfaces with MySQL to reuse existing connections when you attempt to connect. In php, calling mysql_connect() with the same information twice will return the same handle.
It is worth noting, however, that keeping a connection open for too long without querying will cause the connection to timeout. This is usually default of about 8 hours.
Generally, you should open a connection whenever an instance starts needing to access the database. I say instance, because you could have two instances running and they'd need to access the server simultaneously. It's inadvisable to try this multi-instance approach with only 1 super-global connection.
Beyond that, I'm not sure of the overhead of opening and closing a connection. You might want to ask on a mysql forum or forum of the language of your choice.
|