如何在mysql表中为当前年份的每一天创建一个分区

时间:2014-10-08 05:12:04

标签: mysql

实际上我想从最近删除记录的剩余时间起最后三个月存储数据。数据有数百万的记录

1 个答案:

答案 0 :(得分:-1)

您可以使用给定的查询。

CREATE TABLE TABLE_NAME1 (
  id BIGINT(20) NOT NULL AUTO_INCREMENT,
  Ctime DATETIME DEFAULT NULL,
  KEY id (id)
) ENGINE=INNODB AUTO_INCREMENT=286802795 DEFAULT CHARSET=utf8
  PARTITION BY RANGE( TO_DAYS(Ctime) ) (
    PARTITION p1 VALUES LESS THAN (TO_DAYS('2011-04-02')),
    PARTITION p2 VALUES LESS THAN (TO_DAYS('2011-04-03')),
    PARTITION p3 VALUES LESS THAN (TO_DAYS('2011-04-04')),
    PARTITION p4 VALUES LESS THAN (TO_DAYS('2011-04-05')),
    PARTITION p5 VALUES LESS THAN (TO_DAYS('2011-04-06')),
    PARTITION p6 VALUES LESS THAN (TO_DAYS('2011-04-07'))
    );