You can specify the partitioning while creating the table or by executing the ALTER TABLE command. The partition column should be part of all the unique keys in the table.
If you defined partitions based on the created_at column and id is the primary key, you should include the create_at column as part of PRIMARY KEY, that is, (id, created_at).
The following example assumes that there are no foreign keys referenced to the table.
If you wish to implement a partitioning scheme based on ranges or intervals of time in MySQL 8.0, you have two options:
- Partition the table by RANGE, and for the partitioning expression, employ a function operating on a DATE, TIME, or DATETIME column and returning an integer value
- Partition the table ...