MySQLでテーブルに貼られているインデックスを調べる方法

インデックスを調べる

show index from テーブル名;

show index from users;
+-------+------------+----------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name                   | Seq_in_index | Column_name   | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+-------+------------+----------------------------+--------------+---------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| users |          0 | PRIMARY                    |            1 | id            | A         |         100 |     NULL | NULL   |      | BTREE      |         |               |
| users |          0 | users_serial_number_unique |            1 | serial_number | A         |         100 |     NULL | NULL   |      | BTREE      |         |               |

インデックスの追加

ALTER TABLE テーブル名 ADD INDEX インデックス名(インデックスカラム);
ALTER TABLE users ADD INDEX users_serial_number_unique(serial_number);

インデックスの削除

ALTER TABLE テーブル名 DROP INDEX インデックス名;