背景:由于业务变化,mysql表没有多余的字段进行存储,需要改变表结构,然后遇到数据表的数据量比较大。
方法:为了不影响线上的业务,需要多次执行sql语句,并间隔进行休眠,例如:
delete from test_table where id>=98293000 and id<98296000;
select sleep(1);
delete from test_table where id>=98296000 and id<98299000;
select sleep(2);
delete from test_table where id>=98299000 and id<98302000;
select sleep(2);
所以,对于有些表的设计,可以通过增加扩展字段extra_info varchar(1000), 以便业务需要变更时,可以以json格式的字符串存入到extra_info中,无需改变表结构。