1 可以使用ALTER TABLE来进行更改表为分区表,这个操作会创建一个分区表,然后自动进行数据copy然后删除原表。
ALTER TABLE tbl_rtdata PARTITION BY RANGE (Month(fld_date))
(
PARTITION p_Apr VALUES LESS THAN (TO_DAYS('2012-05-01')),
PARTITION p_May VALUES LESS THAN (TO_DAYS('2012-06-01')),
PARTITION p_Dec VALUES LESS THAN MAXVALUE );
2 新建一个和原来表一样的分区表,然后把数据从原表导出,接着倒入新表。
先创建分区表,然后导出原表数据,新表名称改为原表名,然后插入。
CREATE TABLE `news` (
`new_id` int(5) NOT NULL AUTO_INCREMENT,
`new_title` varchar(130) NOT NULL,
`new_type` int(2) NOT NULL,
`new_img` varchar(100) NOT NULL,
`new_desc` text NOT NULL,
`new_user` varchar(100) NOT NULL,
`add_time` varchar(13) NOT NULL,
PRIMARY KEY (`new_id`)
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8
PARTITION BY RANGE (new_id)
(PARTITION p1 VALUES LESS THAN (200) ENGINE = MyISAM,
PARTITION p2 VALUES LESS THAN (400) ENGINE = MyISAM,
PARTITION p3 VALUES LESS THAN (600) ENGINE = MyISAM,
PARTITION p4 VALUES LESS THAN MAXVALUE ENGINE = MyISAM);
表建完之后,只需要吧原表的数据拷贝进新建的表中就好了。