MySQL 5.5 刪除索引的方法

feelpurple發表於2016-06-04
mysql> show keys from dept2;
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name              | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY               |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_deptno      |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_report_date |            1 | report_date | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
3 rows in set (0.00 sec)

方法①

mysql> drop index idx_dept2_deptno on dept2;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show keys from dept2;
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name              | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY               |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
| dept2 |          1 | idx_dept2_report_date |            1 | report_date | A         |           4 |     NULL | NULL   | YES  | BTREE      |         |               |
+-------+------------+-----------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
2 rows in set (0.00 sec)

--方法②

mysql> alter table dept2 drop index idx_dept2_report_date;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show keys from dept2;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| dept2 |          0 | PRIMARY  |            1 | deptno      | A         |           4 |     NULL | NULL   |      | BTREE      |         |               |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
1 row in set (0.00 sec)

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26506993/viewspace-2113870/,如需轉載,請註明出處,否則將追究法律責任。

相關文章