The trick is to add the category field to the current primary key. (Your primary key will remain the primary key)
Then you can break the table into categories.
Here is the code you can use:
ALTER TABLE `products` DROP PRIMARY KEY , ADD PRIMARY KEY ( `id` , `category` ); ALTER TABLE `products` PARTITION BY KEY(category) PARTITIONS 6;
Add the auto_increment parameter to id if you want it to be truly unique, and do not specify the id value when inserting data into the table. The identifier will be determined by the database server upon insertion.
Change the field names and key names as necessary.
Documentation:
Partition Types
Key partioning
Jocelyn
source share