Generate SQL to create indexes in mysql

If you have a mysql database table with indexes and you want to get the alter table  commands to “create” the same indexes on another db

You can run this sql — replacing the tablename with your table.

Just add

alter table TABLENAME

Then paste the add index commands generated by the SQL below

SELECT    concat(‘add index ‘, i.index_name , ‘ using BTREE(‘,
group_concat(i.column_name order by i.seq_in_index), ‘),’) cmd
FROM        information_schema.STATISTICS i      — i for index
WHERE   i.table_name        = ‘DCAS’
GROUP BY     i.index_name

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.