分区字段必须在主键中存在
使用时间分区时,字段类型不支持 timestamp,需改为 datetime
CREATE TABLE `t_log` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '日志ID',
`insert_time` datetime(3) NOT NULL COMMENT '插入时间',
`update_time` timestamp(3) NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '更新时间',
PRIMARY KEY (`id`,`insert_time`)
) ENGINE=InnoDB AUTO_INCREMENT=152 DEFAULT CHARSET=utf8 COMMENT='表'
PARTITION BY RANGE (year(insert_time)) (
PARTITION p2023 VALUES LESS THAN (2023),
......
PARTITION p2033 VALUES LESS THAN (2033)
);