首页 > 数据库技术 > 详细

mysql查看和删除唯一索引

时间:2015-09-30 18:20:05      阅读:394      评论:0      收藏:0      [点我收藏+]

技术分享

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

本文出自 “肖海” 博客,请务必保留此出处http://eveday.blog.51cto.com/10577430/1699531

mysql查看和删除唯一索引

原文:http://eveday.blog.51cto.com/10577430/1699531

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!