千万数据量的表怎么做更新

比如,我有一个t1表,想更新c1字段,就是一个update t1 set c1=1;

但是t1表有1600万行。如何做才能更快?!

我们知道如果直接执行上述语句的话,对于千万级数据量而言肯定是会直接卡死的,所以优先考虑采用存储过程    

如下:

CREATE  PROCEDURE `update_t1`()
BEGIN 
   declare i int;      
   set i = 0;   
   while i <= 27422755 DO   
      update t1 set c1=1  where id>=i and id < i+10000;
      commit;
      set i = i+10000;
   end while;      
end

猜你喜欢

转载自blog.csdn.net/weixin_38964895/article/details/81065082