0

我需要一个 MySQL Skript,它执行以下操作:

删除数据库块,直到删除所有大于 10000 的链接 ID

示例:

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

所以它会删除

DELETE FROM pligg_links WHERE link_id > 10000 and link_id < 20000

然后

DELETE FROM pligg_links WHERE link_id > 20000 and link_id < 30000

直到所有 id 小于 10000 被删除

我需要这个,因为数据库非常非常大(不仅仅是演出)

预先感谢

4

2 回答 2

2

您可以使用该LIMIT语句来调节一步删除多少项目:

DELETE FROM pligg_links
WHERE link_id > 10000
LIMIT 1000;

http://dev.mysql.com/doc/refman/5.1/en/delete.html说:

The MySQL-specific LIMIT row_count option to DELETE tells the server the maximum number of rows to be deleted before control is returned to the client. This can be used to ensure that a given DELETE statement does not take too much time. You can simply repeat the DELETE statement until the number of affected rows is less than the LIMIT value.

You could determine the number of deleted rows by using SELECT ROW_COUNT(); if you would like automatize deletion:

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_row-count

于 2012-06-19T09:22:46.367 回答
1

::中的问题是什么

DELETE FROM pligg_links WHERE link_id > 10000

还有另一种方法:(只需按顺序执行这3个查询)

Step1 : Insert into pligg_links_temp select * from pligg_links where link_id < 10000;
Step2 : Drop pligg_links;
Step3 : Insert into pligg_links select * from pligg_links_temp
于 2012-06-19T09:19:03.213 回答