Search code examples
mysqlindexingalter-table

MySQL dropping all indexes from table


I have a MySQL database that runs for some time now with many changes on it. Lately I looked over it and I noticed that in some cases I have doubled the index on the same field. Some Indexes are missing, and in general there is a huge mess in all the indexes.

I wants to drop all indexes from a table. Later on I have a prepared script that will run ALTER TABLE and add the relevant indexes.

Is there a way to drop all indexes from a table?


Solution

  • If you have phpmyadmin or any similar tool you can do that very easily graphically.

    Or for every index do something like

    ALTER TABLE  `table` DROP INDEX  `NameIndex`
    

    You can get the indexes with

    SHOW INDEX FROM `table`