먼저 MySQL에서 인덱스를 표시하는 방법을 살펴보겠습니다. 이를 위해 SHOW 명령을 사용하십시오.
인덱스를 표시하는 쿼리는 다음과 같습니다. -
mysql> SHOW INDEX FROM indexingdemo;
다음은 출력입니다.
+--------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | +--------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ | indexingdemo | 1 | indexName | 1 | Name | A | 0 | NULL | NULL | YES | BTREE | | | YES | +--------------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+ 1 row in set (0.17 sec)
다음 쿼리를 사용하여 MySQL 인덱스 목록을 얻을 수 있습니다.
그 전에 먼저 구문을 살펴보겠습니다.
SELECT DISTINCT TABLE_NAME, INDEX_NAME FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = 'yourDatabaseName';
이제 위의 구문을 적용하여 MySQL 인덱스 목록을 가져오도록 하겠습니다.
mysql> SELECT DISTINCT -> TABLE_NAME, -> INDEX_NAME -> FROM INFORMATION_SCHEMA.STATISTICS -> WHERE TABLE_SCHEMA = 'business';
다음은 인덱스 목록을 표시하는 출력입니다.
+--------------------------+------------------+ | TABLE_NAME | INDEX_NAME | +--------------------------+------------------+ | addcolumntable | Name_Index | | addingautoincrement | PRIMARY | | addingunique | name | | autoincrement | PRIMARY | | autoincrementtable | PRIMARY | | bookindexes | BookName | | childdemo | ConstChild | | clonestudent | idIndex | | clonestudent | NameStuIndex | | college | PRIMARY | | compositeprimarykey | PRIMARY | | demoauto | PRIMARY | | demoindex | PRIMARY | | demoschema | idDemoIndex | | duplicatebookindexes | BookName | | employeeinformation | PRIMARY | | foreigntable | constFKPK | | foreigntabledemo | FKConst | | functionindexdemo | indFirstName | | indexingdemo | indexName | | keydemo | PRIMARY | | lastinsertrecordiddemo | PRIMARY | | multipleindexdemo | id | | nextiddemo | PRIMARY | | parentdemo | PRIMARY | | primarytable | PRIMARY | | primarytable1 | PRIMARY | | primarytabledemo | PRIMARY | | schemadatabasemethoddemo | PRIMARY | | sequencedemo | PRIMARY | | student | idIndex | | student | NameStuIndex | | studentenrollment | StudCollegeConst | | tabledemo2 | ConstFK | | tabledemo3 | ConstFK | | tablepri | PRIMARY | | tblf | ConstFK | | tblp | PRIMARY | | transcationdemo | PRIMARY | | triggedemo | PRIMARY | | uniqueautoid | id | | uniqueconstdemo | name | | uniquedemo | name | | uniquedemo1 | id | | updtable | PRIMARY | | usernameandpassworddemo | PRIMARY | | usernameandpassworddemo | UserId | +--------------------------+------------------+ 47 rows in set (0.07 sec)