I need a way to update tables on live machine without affecting users experience.
I have few tables on MyISAM engine which are being updated every 15 minutes. Update script just truncates table and inserts data from select sentence. Problem appears then user tries to view information from table which is being updated – user experience lags, uncorrect information is being shown.
It would be easy to do with InnoDB transactions, but what about MyISAM?
You might try this kind of thing if you MUST use myISAM. You need to be at version 5.0 or higher. If you’re not, upgrade.
If you can make the software you’re using to read this resilient to a SQL error that complains about a missing table, and simply have it try again after a second or so, you can skip the locking and unlocking steps. But those steps protect your system from the brief moment, during the renaming shuffle where there’s no table with the correct name for the production table.
This is monkey business, and takes a bit of debugging. But it has worked very well for me.
(I define “monkey business” to be stuff outside the scope of pure, elegant, SQL.)