若表数据比较大,直接update会时间很慢,造成锁表,内存不够等问题,可以使用存储过程分批次进行更新提交,where条件最好加上索引,当然也可以批次删除;
drop procedure if exists upt_tbl_nm;
delimiter //
create procedure upt_tbl_nm()
begin
declare ncnt int default 0;
declare nrow int default 0;
select count(*) into nrow from tbl_nm;
repeat
update tbl_nm set trans_dt='20200113' where trans_dt='20190113' limit 5000;
set ncnt=ncnt+5000;
until ncnt >= nrow
end repeat;
end;
//
delimiter ;
call upt_tbl_nm();
drop procedure if exists upt_tbl_nm;