首页 > 数据库 >Mysql之以月为单位给表建立分区

Mysql之以月为单位给表建立分区

时间:2023-01-18 17:45:46浏览次数:38  
标签:给表 01 之以 LESS PARTITION DAYS VALUES Mysql THAN

以月为单位给表建立分区

ALTER TABLE xxxx PARTITION BY RANGE (to_days(`CREATE_TIME`))
(
PARTITION from202301 VALUES LESS THAN (TO_DAYS('2023-02-01')),
PARTITION from202302 VALUES LESS THAN (TO_DAYS('2023-03-01')),
PARTITION from202303 VALUES LESS THAN (TO_DAYS('2023-04-01')),
PARTITION from202304 VALUES LESS THAN (TO_DAYS('2023-05-01')),
PARTITION from202305 VALUES LESS THAN (TO_DAYS('2023-06-01')),
PARTITION from202306 VALUES LESS THAN (TO_DAYS('2023-07-01')),
PARTITION from202307 VALUES LESS THAN (TO_DAYS('2023-08-01')),
PARTITION from202308 VALUES LESS THAN (TO_DAYS('2023-09-01')),
PARTITION from202309 VALUES LESS THAN (TO_DAYS('2023-10-01')),
PARTITION from202310 VALUES LESS THAN (TO_DAYS('2023-11-01')),
PARTITION from202311 VALUES LESS THAN (TO_DAYS('2023-12-01')),
PARTITION from202312 VALUES LESS THAN (TO_DAYS('2024-01-01'))
);

按分区查数据

SELECT * FROM XXX PARTITION(from202301);

标签:给表,01,之以,LESS,PARTITION,DAYS,VALUES,Mysql,THAN
From: https://www.cnblogs.com/vaen/p/17060302.html

相关文章