wKioL1X6iCGhIIqkAACNkbOZ8S8981.jpg

1、案例要求

需要删除urapport_main库中userid_mobileno表中mobileno字段的唯一性索引

2、做法

1. 备份之前的数据库中的表

# mysqldump -uroot -psecret urapport_main userid_mobilenouserid_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