Skip to main content
edited title
Link
Aaron Bertrand
  • 181.5k
  • 28
  • 402
  • 619

How to "swap" out production tables in MySql

edited tags
Link
RolandoMySQLDBA
  • 184.4k
  • 33
  • 323
  • 531
Source Link

How to "swap" out production tables in MySql

I have a MySQL table that holds a few thousand records which go out of date very quickly. A few times a day we run a slow process which needs to pull data from multiple sources and re-populate the table.

The catch is the table needs to be available all the time. My initial idea was to do the slow population process on a temp table, then drop the live table and rename the temp table to replace the live table.

Is it possible to lock the live table before the drop/rename process so that queries will be delayed and not lost?

Or is this the wrong approach?