I have a MySQL 8 server on a virtual machine. I'd like to start it up when another server wants to communicate with it, and shut it down some time after there hasn't been any connections or queries.

Right now I'm polling the VM to get it somewhat working, but there's gotta be a better way.

I read the MySQL docs on handling Unix signals, but there isn't a "startup" type signal.

I also read about MySQL events, but those seem to be limited to operations within the database like SQL queries.

Does MySQL have a way to push events to a remote server on startup, shutdown, error, etc.?

It's probably possible to achieve in a script on the OS, and then send a curl request to the remote server with appropriate info, but MySQL's a big software and I'm curious if this functionality is hidden somewhere in it.

有帮助吗?

解决方案

Such a feature cannot be in mysqld in the cloud.

In order not to pay for a cloud VM, it must be totally down. That means that communication with it must be preceded by restarting your image. Only then is mysqld awake. At that point, it is ready to receive connections. (And you must "connect" before doing "insert" or whatever you need to do.)

So, your "it's probably possible ..." paragraph is the approach to take.

To add to the complexity, there is probably no easy way to "automatically shut down" the VM after an idle period. Consider having your "restart" script wait a few minutes, then shutdown. (Where "a few minutes" is tuned to accommodate your typical activity time.)

For security reasons, MySQL deliberately has no built-in way to communicate with the rest of the world. (A common request is to send an email based on some data change.)

Another thing to look into -- a proxy between your clients and the VM-MySQL server. The proxy would live on the client machine(s). It might be able to orchestrate the startup. (There are many Proxy products out there; they are aimed at other things -- HA, sharding, routing, load balancing, etc.)

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top