Mysql 大批量数据插入与删除

2022-10-07 14:08:28

Mysql 大批量数据插入与删除

1.插入

分批次插入

5w条数据,每次插入5000,总耗时在50s左右

2.删除

mysql一次性删除大量数据是有可能造成死锁的,而且也会抛异常
The total number of locks exceeds the lock table size in MySQL
这是由于需要删除的数据太大,mysql给的buffer好像只有8MB左右
lock wait timeout exceed 超时

加索引、计算maxId,统计数目count

SELECT max(id) from indonesia_camp_pit where timestamp <时间
SELECT count(*) from indonesia_camp_pit where id <maxId

循环分批次删除

delete from indonesia_camp_pit where id <maxId limit 10000

 每次删除1w条耗时300ms-500ms左右,总共删除100w-200w耗时30s

posted @ 2019-05-16 11:08诸葛子房 阅读(...) 评论(...)编辑收藏

  • 作者:诸葛子房_
  • 原文链接:https://blog.csdn.net/weixin_43291055/article/details/92616952
    更新时间:2022-10-07 14:08:28