MySQL 创建唯一索引忽略对已经重复数据的检查
MySQL 创建唯一索引忽略对已经重复数据的检查
在创建唯一索引的基础上加上关键字"IGNORE "即可。
# 重复数据 mysql> select aid,count(aid) as total ,email,tel_no,account_type,exten,passwd from fudao_admin group by user_name having total> 1; +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ | aid | total | email | tel_no | account_type | exten | passwd | +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ | 256 | 5 | | | 0 | | | | 4712 | 2 | [email protected] | 0 | 0 | | 1afc079897c2de73022540f7c31db632 | | 1070 | 2 | [email protected] | | 0 | | c81103a50f7b7748303ede9726eed91a | | 10429 | 2 | [email protected] | 0 | 0 | 1090 | 9bd7aa138ff1486e1285a412bda934dd | | 10425 | 2 | [email protected] | 0 | 0 | | 96e79218965eb72c92a549dd5a330112 | | 10426 | 2 | [email protected] | 0 | 0 | | 96e79218965eb72c92a549dd5a330112 | | 1402 | 2 | [email protected] | | 0 | | 72d1e186ab204c937ea48a3ff9f926fa | | 3385 | 2 | [email protected] | 0 | 0 | | 263cad88649b39ed9fc95739c4f20edc | +-------+-------+--------------------------+--------+--------------+-------+----------------------------------+ 8 rows in set (0.25 sec)
mysql> ALTER IGNORE TABLE fudao_admin ADD UNIQUE `uq_user_name` (user_name); Query OK, 13530 rows affected, 1 warning (0.44 sec) Records: 13530 Duplicates: 11 Warnings: 1
mysql> select aid,count(aid) as total ,email,tel_no,account_type,exten,passwd from fudao_admin group by user_name having total> 1; Empty set (0.08 sec)
相关推荐
gululululu 2020-05-21
mycosmos 2020-01-11
adsadadaddadasda 2020-01-07
cyhgogogo 2020-01-06
mjperhuo 2019-11-17
shouen 2019-04-02
飞轩亭 2019-09-03
wenchanter 2013-08-09
bowei0 2013-05-08
zry 2012-05-31
wangxingg 2019-07-01
tanyhuan 2019-06-30
死锁的本质是资源竞争,批量插入如果顺序不一致很容易导致死锁,我们来分析一下这个情况。为了方便演示,把批量插入改写为了多条 insert。t1 t2 begin; begin; insert ignor
zbz0 2019-06-13
Supercell 2019-06-28
cnzou 2011-04-16
hejunbinfendou 2019-05-22
蚂蚁爱吃糖 2011-09-26
zhuzhufxz 2019-05-27
lirenkai000 2015-04-13