这是一个很难理解的问题,但是,有一个表需要截断,同时插入新的寄存器,但是在此过程中,网站访问者看不到网站内容上没有任何内容,我该怎么做在像 --single-transation 这样的 SQL 中,在新的到来之前有类似“缓存寄存器”的东西?
最佳答案
使用rename table切换 2 个表。
RENAME TABLE, unlike ALTER TABLE, can rename multiple tables within a single statement:
- 准备新表
the_table_next
(可能是一个很长的操作) RENAME TABLE the_table TO the_table_prev, the_table_next To the_table;
(非常快的操作)- 删除/截断表
the_table_prev
When you execute RENAME TABLE, you cannot have any locked tables or active transactions. With that condition satisfied, the rename operation is done atomically; no other session can access any of the tables while the rename is in progress.
If any errors occur during a RENAME TABLE, the statement fails and no changes are made.
注意:
使用alter table rename
,您需要使用2个命令==> 2个不同的事务(DDL指令)
带有重命名表
=> 单个事务
关于mysql - 我需要截断一个表然后插入新的寄存器,但用户看不到这个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47479122/