1、案例要求
需要删除urapport_main库中userid_mobileno表中mobileno字段的唯一性索引
2、做法
1. 备份之前的数据库中的表
# mysqldump -uroot -psecret urapport_main userid_mobileno> userid_mobileno.sql
2. 先切到urapport_main 数据库
mysql> use urapport_main;
3. 查询userid_mobileno表中的索引
mysql> show index from userid_mobileno;
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| userid_mobileno | 0 | PRIMARY | 1 | userid | A | 2196 | NULL | NULL | | BTREE | | |
| userid_mobileno | 0 | mobileno | 1 | mobileno | A | 2196 | NULL | NULL | YES | BTREE | | |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set
4. 删除userid_mobileno表中的mobileno索引
mysql> alter table userid_mobileno drop index mobileno;
Database changed
Records: 0 Duplicates: 0 Warnings: 0
5. 验证是否删除 ,没有第二条即删除成功
mysql> show index from userid_mobileno;
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| userid_mobileno | 0 | PRIMARY | 1 | userid | A | 2196 | NULL | NULL | | BTREE | | |
+-----------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set
本文出自 “肖海” 博客,请务必保留此出处http://eveday.blog.51cto.com/10577430/1699531
原文:http://eveday.blog.51cto.com/10577430/1699531