简体   繁体   English

MySQL-锁定和刷新特定表的未决数据

[英]Mysql - lock and flush pending data for a specific table

I need to temporarily rename a table. 我需要临时重命名表。 There are inserts to this table all the time. 该表一直都有插入。 So the idea is to lock the table for writing and reading, then flush all the possible pending inserts, then rename the table, do a couple of things, rename the table back and unlock it so it will be usable again. 因此,想法是锁定表以进行读写,然后刷新所有可能的未决插入,然后重命名表,做几件事,将表重命名并解锁,以使其再次可用。

What steps should one take to achieve that (or closest as possible) task? 一个人应该采取什么步骤来完成该任务(或尽可能接近的任务)?

Thanks! 谢谢!

Ok, figured it out. 好,知道了。

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

Or 要么

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`;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM