1.key分区语句:
ALTER TABLE order_info PARTITION BY KEY(orderSn) PARTITIONS 127;
2.rang分区语句:
ALTER TABLE `table` partition by range(to_days(entertime)) (partition P0 values less than (to_days('2018-01-01')))
这里面需要生成一套代码:
<?php
$total = 257;
$str = "ALTER TABLE `order_goods`
partition by range(to_days(addTime))
(";
$time = "2019-07-01";
for($i=0;$i<=$total;$i++){
$stringTime = date('Ym',strtotime($time));
$newTime = date('Y-m-d',strtotime("+1 month",strtotime($time)));
//$strTime = date('Ymd',strtotime("+1 month",strtotime($time)));
$time = &$newTime;
$pName = 'p'.$stringTime;
$str .=" PARTITION ".$pName." VALUES LESS THAN (to_days('".$newTime."')) ENGINE = InnoDB,<br />";
}
$str .=");";
echo $str;exit;
?>
3.删除分区表:
alter table user_collection REMOVE PARTITIONING