Mysql - 锁定并清除特定 table 的未决数据

Mysql - lock and flush pending data for a specific table

我需要临时重命名一个table。这个 table 一直都有插入。所以想法是锁定 table 进行写入和读取,然后刷新所有可能的挂起插入,然后重命名 table,做几件事,重命名 table 并解锁这样它就可以再次使用了。

应该采取哪些步骤来完成该(或尽可能接近的)任务?

谢谢!

好的,明白了。

lock tables sometable write;
flush tables sometable;
unlock tables; rename table `sometable` to `sometable_locked`;
-- do something useful
rename table `sometable_locked` to `sometable`;

或者

lock tables sometable write;
flush tables sometable;
alter table `sometable` rename to `sometable_locked`;
-- do something useful
unlock tables; alter table `sometable_locked` rename to `sometable`;