mysql delete千萬數據操作 在mysql中,delete掉上千萬條數據時,會造成表被鎖,甚至給mysql服務器帶來很大壓力。這是目前mysql無法避免的一個問題,可以說是在處理大數據量方面的不足。而在業務中,又無法避免這種delete需求,因此,借用oracle的思想,寫存儲過程,分而治之,批量刪掉。 delimiter $$ create procedure sp_del_test() begin declare done int default 0; declare uid_1 int default 0; declare i int default 0; declare cur_test cursor for select uid from tmp_test_del; declare continue handler for SQLSTATE '02000' set done=1; open cur_test; repeat fetch cur_test into uid_1; set autocommit=0; delete from test_fenye where uid=uid_1; set i=i+1; if mod(i,1000)=0 then commit; end if; until done=1 end repeat; close cur_test; commit; end; $$