create table sign_in_log(unid BIGINT(20) NOT NULL,
create_time datetime not null)engine = innodb default charset=utf8 partition by range columns (create_time)(
PARTITION P_20220623
VALUES LESS THAN ('2022-06-24 00:00:00') ENGINE=INNODB,
PARTITION P_20220624
VALUES LESS THAN ('2022-06-25 00:00:00') ENGINE = INNODB
);
注意,分区表其实是需要每天进行创建的,可以写个定时任务,但是可以一开始先创建几天的,然后后面每天定时任务创建一天的,这里是根据create_time字段来创建分区;
可以通过来查询最近5天的分区以及每个分区当前的数据量:
select PARTITION_NAME AS '分区名', TABLE_ROWS AS '表该分区行数' from information_schema.partitions where table_schema = "db_test" and table_name = "sigin_in_log" order by PARTITION_NAME desc limit 5