MySQL controlling shutdown We are running a financial application using MySQL as database.

For  performance reasons  we are using memory tables for a few of our live tables where the data is populated ever few milli seconds.

To ensure data consistency in all scenarios (planned and unplanned outages)  we need to ensure that the data in the memory tables are always persisted for that  we are planning to implement shutdown hooks, wherein n case of any shutdown the data would be written in normal tables  and restored during start-up.

I am unfortunately not able to find a way to do it.

Any suggestions would be appreciated.

We are using MySQL ver 5.7
Don't even try.

InnoDB has years of optimization behind it.  It persists to disk even across unplanned power failures due to its integrated logs.

Furthermore, because of MEMORY using table locks (as opposed to InnoDB's row locks), there are benchmarks that say that InnoDB is faster than MEMORY.  There could be cases where Memory is faster than InnoDB.  But between your moderately high write rate and the JOINs, InnoDB is very likely to have less interference between the two tasks.

If you want full persistence, you need to write to the disk 500 times per second.  Are you using SSDs?  RAID?  An ordinary HDD cannot run at 500 flushes per second.  If you have a fast enough drive, you may as well let InnoDB take care of everything for you.

InnoDB's automatic saving and restoring across power failures is very likely to be faster, and much less programming effort for you.