表分区

#设置主键

ALTER TABLE playstats DROP PRIMARY KEY,ADD PRIMARY KEY(id,startTime);

-------------------------------------------------------------------------------------

#初始化分区

ALTER TABLE playstats PARTITION BY RANGE(TO_DAYS(startTime))( 

PARTITION p0 VALUES LESS THAN (TO_DAYS('2013-12-29 00:00:00')), 

PARTITION p1 VALUES LESS THAN (TO_DAYS('2013-12-30 00:00:00')), 

PARTITION p2 VALUES LESS THAN (TO_DAYS('2013-12-31 00:00:00')), 

PARTITION p3 VALUES LESS THAN (TO_DAYS('2014-01-01 00:00:00')),

PARTITION p4 VALUES LESS THAN (TO_DAYS('2014-01-02 00:00:00')),

PARTITION p5 VALUES LESS THAN (TO_DAYS('2014-01-03 00:00:00'))

);

---------------------------------------------------------------------------------------

#自动增加分区

ALTER TABLE playstats ADD PARTITION (PARTITION p6 VALUES LESS THAN (TO_DAYS('2014-01-04 00:00:00')));

---------------------------------------------------------------------------------------

select 
  partition_name part,  
  partition_expression expr,  
  partition_description descr,  
  table_rows  
from information_schema.partitions  where 
  table_schema = schema()  
  and table_name='test';

----------------------------------------------------------------------------------------

show create table playstats;




你可能感兴趣的:(mysql,表分区)