当表数据量是几百万条以上时,如果要修改原表结构,比如给原表加个列字段,同时在这个表上加索引。

请勿使用以下方式:

alter table video_names add column type VARCHAR(255) NOT NULL, add index(type)

原因是:

经过实际测试,表数据量是800多万条,运行上述语句时,几个小时执行不完。

正确方式:

1、创建一个新表tmp_names

2、执行insert into tmp_names(****) select ***** from video_name;

3、删除video_names

4、重命名tmp_name为video_names;语句为rename table tmp_names to video_names;