Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rename all the indexes in MySQL

Tags:

mysql

I have a MySQL database where the names of indexes are shared between tables. Which is fine in MySQL, because index names only have to be unique within a table, and not within a database. But I have to export this database to a system that requires index name be globally unique.

Is there some command or script I can run to assign unique names to the indexes? I don't care if they are randomly generated.

like image 760
Phyxx Avatar asked Oct 04 '22 15:10

Phyxx


2 Answers

As of the latest version of MySQL, there is no way to rename indexes. Your only option would be to DROP the index then CREATE a new one or just CREATE a new one.

like image 119
jagc Avatar answered Oct 11 '22 15:10

jagc


There is no RENAME or ALTER index command on MySQL. You need to either DROP the index or CREATE a new one.

like image 23
Shankar Narayana Damodaran Avatar answered Oct 11 '22 15:10

Shankar Narayana Damodaran