Reputation: 4136
Is there a way to keep a mysql server stopped and for it to be started only after a connection is attempted.
I have a development mysql server in my ubuntu machine and I would like to keep it stopped unless needed and I don't want to have to remember to start it manually.
It's ok if this can be solved using something like vagrant or docker.
Bonus point if the server can be shut down after a configurable amount of idle time.
I remember openshift did something like this, if not connections were made the vm would be shut down and be started only after some connection was attempted to it.
Upvotes: 0
Views: 70
Reputation: 562891
Any MySQL client will attempt to connect to port 3306 (by default) to establish a MySQL connection. If the MySQL server is not running, there's nothing listening on port 3306, so the connection will simply fail.
To do what you're describing, there would need to be something listening on port 3306. Perhaps a proxy of some kind, like HAProxy or ProxySQL. Perhaps one of these can be configured to start a service on demand, but I've never seen anyone attempt to do that.
The reason is that it takes some time to start up a MySQL server process. At least a few seconds, but it could be much longer, depending on whether the server needs to perform crash recovery if it wasn't shut down cleanly last time it stopped. The proxy that starts it would have to keep re-trying the connection until it responds.
There's also a possibility that a downed MySQL server cannot be started, for example if there's a configuration problem that prevents it from starting, or a corrupted database. Then your client would try repeatedly to connect, with a delay each time, and never be able to start the service.
I wonder if what you really need is not MySQL, but an embedded database like SQLite.
Upvotes: 1