在我的MySQL表中包含超过2000万条记录。我想通过运行从较低的索引中删除它

delete FROM mydb.dailyreportdetails where idDailyReportDetails>0 order by idDailyReportDetails asc limit 1000 ;


在运行上面的查询时,出现以下错误

Operation failed: There was an error while applying the SQL script to the database.
ERROR 1205: 1205: Lock wait timeout exceeded; try restarting transaction
SQL Statement:


有没有什么办法可以在mysql后台运行查询或以更快的速度删除这些记录?

最佳答案

您可以先找到要删除的实际ID ...

SELECT idDailyReportDetails
    FROM mydb.dailyreportdetails
    where idDailyReportDetails>0
    order by idDailyReportDetails asc limit 1000,1 ;


然后使用选择的值直接删除...

DELETE FROM mydb.dailyreportdetails
        where idDailyReportDetails < ID;

09-12 16:03