CREATE TABLE `xxxxxxxx` (
`crttm` int(11) NOT NULL,
`srvid` int(11) NOT NULL,
`evtid` int(11) NOT NULL,
`aid` int(11) NOT NULL,
`rid` int(11) NOT NULL,
`itmid` int(11) NOT NULL,
`itmnum` int(11) NOT NULL,
`gdtype` int(11) NOT NULL,
`gdnum` int(11) NOT NULL,
`islmt` int(11) NOT NULL,
KEY `crttm` (`crttm`),
KEY `itemid` (`itmid`),
KEY `srvid` (`srvid`),
KEY `gdtype` (`gdtype`)
) ENGINE=myisam DEFAULT CHARSET=utf8
PARTITION BY RANGE (crttm)
(
PARTITION p201303 VALUES LESS THAN (unix_timestamp(‘2013-04-01‘)),
PARTITION p201304 VALUES LESS THAN (unix_timestamp(‘2013-05-01‘)),
PARTITION p201305 VALUES LESS THAN (unix_timestamp(‘2013-06-01‘)),
PARTITION p201306 VALUES LESS THAN (unix_timestamp(‘2013-07-01‘)),
PARTITION p201307 VALUES LESS THAN (unix_timestamp(‘2013-08-01‘)),
PARTITION p201308 VALUES LESS THAN (unix_timestamp(‘2013-09-01‘)),
PARTITION p201309 VALUES LESS THAN (unix_timestamp(‘2013-10-01‘)),
PARTITION p201310 VALUES LESS THAN (unix_timestamp(‘2013-11-01‘)),
PARTITION p201311 VALUES LESS THAN (unix_timestamp(‘2013-12-01‘)),
PARTITION p201312 VALUES LESS THAN (unix_timestamp(‘2014-01-01‘)),
PARTITION p201401 VALUES LESS THAN (unix_timestamp(‘2014-02-01‘))
);
1. primary key和unique key必须包含在分区key的一部分,否则在创建primary key和unique index时会报”ERROR 1503 (HY000)“
2. 范围分区添加分区只能在最大值后面追加分区
3. 所有分区的engine必须一样
4. 范围分区分区字段:integer、数值表达式、日期列,日期函数表达式(如year(),to_days(),to_seconds(),unix_timestamp())