MySQL partitions InnoDB tables natively. Two rules shape the design. Every unique key, including the primary key, must contain every column the partitioning uses. And partitioned InnoDB tables cannot have foreign keys, in either direction.
CREATE TABLE events (
id BIGINT NOT NULL AUTO_INCREMENT,
created_at DATETIME NOT NULL,
account_id BIGINT NOT NULL,
payload JSON,
PRIMARY KEY (id, created_at),
KEY (account_id, created_at)
)
PARTITION BY RANGE COLUMNS (created_at) (
PARTITION p2026_11 VALUES LESS THAN ('2026-12-01'),
PARTITION p2026_12 VALUES LESS THAN ('2027-01-01'),
PARTITION pmax VALUES LESS THAN (MAXVALUE)
);
-- next month: split the catch-all before data lands in it
ALTER TABLE events REORGANIZE PARTITION pmax INTO (
PARTITION p2027_01 VALUES LESS THAN ('2027-02-01'),
PARTITION pmax VALUES LESS THAN (MAXVALUE));
-- retention: milliseconds, not hours
ALTER TABLE events DROP PARTITION p2026_11;Keep pmax empty. Reorganizing an empty partition is quick. Reorganizing one that already holds a month of rows copies all of them. EXPLAIN shows a partitions column, which is how you confirm pruning.
SELECT TABLE_NAME, PARTITION_NAME, TABLE_ROWS
FROM information_schema.PARTITIONS
WHERE PARTITION_NAME IS NOT NULL
ORDER BY TABLE_NAME, PARTITION_ORDINAL_POSITION
LIMIT 20;