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