MySQL script to delete data in chunks until everything lower then id has been deleted

Posted by Chriswede on Stack Overflow See other posts from Stack Overflow or by Chriswede
Published on 2012-06-19T09:13:53Z Indexed on 2012/06/19 9:16 UTC
Read the original article Hit count: 265

I need an MySQL Skript which does the following:

delete chunks of the database until it has deleted all link_id's greater then 10000

exmaple:

x = 10000
DELETE FROM pligg_links WHERE link_id > x and link_id < x+10000
x = x + 10000
...

So it would delete

DELETE FROM pligg_links WHERE link_id > 10000 and link_id < 20000

then

DELETE FROM pligg_links WHERE link_id > 20000 and link_id < 30000

until all id's less then 10000 have been removed

I need this because the database is very very big (more then a gig)

thank in advance

© Stack Overflow or respective owner

Related posts about mysql

Related posts about script