How do I swap tables in MySQL?
Use this one command:

RENAME TABLE foo TO foo_old, foo_new To foo;


It is an atomic operation: both tables are locked together (and for a very short time), so any access occurs either before or after the RENAME.