mysql查看和刪除唯一索引

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章