>  기사  >  데이터 베이스  >  MySQL delete 千万数据操作

MySQL delete 千万数据操作

WBOY
WBOY원래의
2016-06-07 17:29:411134검색

在mysql中,delete掉上千万条数据时,会造成表被锁,甚至给mysql服务器带来很大压力。这是目前mysql无法避免的一个问题,可以说是

在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;
 $$

linux

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.