最近项目中有个需求,要对三个字段进行唯一索引,语句很简单:
alter table tuser_props_pay add unique index(userno,propsno,datatime);
但是由于有重复数据需要加入ignore,对重复数据进行忽略并只保留一条相同数据。这时语句改为:
alter ignore table tuser_props_pay add unique index(userno,propsno,datatime);
应该没问题的语句却在执行过程中报错:MySQL server version for the right syntax to use near ignore...
找了很多原因,最后确定为mysql5.7版本不在支持ignore,由于不知道哪条是第一条的数据,所以会引起重复数据问题,以及唯一字段等问题。
但是不能用ignore就意味着要么降低mysql版本,要么手动去重。
附:mysql5.7不支持ignore官方解释:http://dev.mysql.com/worklog/task/?id=7395