MySQL dropping all indexes from table

后端 未结 4 740
小鲜肉
小鲜肉 2021-01-17 10:27

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 fi

4条回答
  •  难免孤独
    2021-01-17 10:36

    In Ruby on Rails I do this:

    indexes = ActiveRecord::Base.connection.execute("SHOW INDEX FROM tablename")
    indexes.each do |index|
      ActiveRecord::Base.connection.execute("ALTER TABLE tablename DROP INDEX #{index[2]};")
    end
    

提交回复
热议问题