Search code examples
mysqlinnodbpartitioning

how to alter a mysql innodb partition to use another key?


I have a table with 5 hash(key_1) partitions. I want to change that, so it instead has 5 hash(key_2) partitions, but without losing data.

How do I do this? I have searched but its hard to find confirmation that I dont lose data by deleting partitions.


Solution

  • Deleting, truncating, or dropping partitions will definitely lose data. You can change partitioning this with ALTER TABLE, for example ALTER TABLE t PARTITION BY HASH (key_2) PARTITIONS 5. This won't lose data, but (at least with InnoDB), the table will be locked for writes and rebuilt with the new partitioning.