MySQL table partition by month from unix timestamp



1. Create column with data type 'date'  

2. insert into data type date (u can insert using update from timestamp or etc)

3. create partition table using this command


ALTER TABLE t_history_trend_test PARTITION BY RANGE (month(to_date))

(

PARTITION JAN VALUES LESS THAN (2),

PARTITION FEB VALUES LESS THAN (3),

PARTITION MAR VALUES LESS THAN (4),

PARTITION APR VALUES LESS THAN (5),

PARTITION MAY VALUES LESS THAN (6),

PARTITION JUN VALUES LESS THAN (7),

PARTITION JUL VALUES LESS THAN (8),

PARTITION AUG VALUES LESS THAN (9),

PARTITION SEP VALUES LESS THAN (10),

PARTITION `OCT` VALUES LESS THAN (11),

PARTITION NOV VALUES LESS THAN (12),

PARTITION `DEC` VALUES LESS THAN MAXVALUE);

how to select data from spesific partition table ?
do -> select * from t_history_trend partition(JAN) limit 10;

the "partition(jan) for show data from partition table januari"

Posting Komentar

Lebih baru Lebih lama