开发者

PHP/MYSQL - Backing up mysql data that changes by the second

开发者 https://www.devze.com 2022-12-14 13:57 出处:网络
I 开发者_StackOverflow社区have a mysql table (A) that\'s taking in hundreds to thousands of inserts per second. Every 15 minutes I\'d like to move all that data to table (B) and delete all the data fr

I 开发者_StackOverflow社区have a mysql table (A) that's taking in hundreds to thousands of inserts per second. Every 15 minutes I'd like to move all that data to table (B) and delete all the data from (A) without interrupting/missing the new rows going in.

Suggestions? Tips?


You could copy the rows, and then delete only those rows that were copied:

insert into B (keycol, col1, col2)
select keycol, col1, col2 from A

Then delete rows in A that are already in B:

delete A
from A
inner join B on A.key = B.key

Alternative syntax:

delete from A
where exists (
    select * from B where A.key = B.key
)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号