1. 数据库添加索引
alter table dir_list add index dir_name(dir_name);
alter table dir_list add index file_name(file_name);
alter table dir_list add index file_size(file_size);
alter table dir_list add index client_id(client_id);
alter table dir_list add index task_name(task_name);
2.去重
先添加主键,并设置为自增
alter table dir_list add primary key(id);
alter table dir_list modify column id int(11) not null auto_increment first,add primary key(id);
alter table dir_list add index task_name(task_name); //添加索引
再删除重复记录
DELETE from dir_list where id not in (select d.id from (SELECT id FROM dir_list GROUP BY dir_name,file_name,client_id)as d)
转载请注明:exchen's blog » mysql数据库添加索引和去重