月別に別ける場合
ALTER TABLE テーブル名 PARTITION BY RANGE COLUMNS(created_at) ( PARTITION p201610 VALUES LESS THAN ('2016-11-01 00:00:00') COMMENT='2016-10', PARTITION p201611 VALUES LESS THAN ('2016-12-01 00:00:00') COMMENT='2016-11', : : PARTITION p201912 VALUES LESS THAN ('2020-01-01 00:00:00') COMMENT='2019-12', PARTITION pmax VALUES LESS THAN MAXVALUE )
SELECT TABLE_SCHEMA,PARTITION_NAME,PARTITION_ORDINAL_POSITION,TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME="テーブル名"
SQL コマンドの前に “EXPLAIN PARTITIONS” を付ける。
EXPLAIN PARTITIONS SELECT * FROM テーブル名 WHERE created_at >= "2016-10-01 00:00:00" && created_at < "2016-12-01 00:00:00"
ALTER TABLE テーブル名 DROP PARTITION パーティション名