是指根据一定规则,将数据库中的一张表分解成多个更小的,容易管理的部分。从逻辑上看,只有一张表,但是底层却是由多个物理分区组成。
例如:
CREATE TABLE `rangeyear_t1_kafka_consume_log` (
`id` int(11) NOT NULL COMMENT 'id',
`create_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '消息接收时间',
PRIMARY KEY (`id`,`create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
PARTITION BY RANGE (YEAR(create_time))
(PARTITION p2012 VALUES LESS THAN (2012) ENGINE = InnoDB,
PARTITION p2013 VALUES LESS THAN (2013) ENGINE = InnoDB,
PARTITION p2014 VALUES LESS THAN (2014) ENGINE = InnoDB);
cnsz22pl0015:cmdpsit > ll|grep rangeyear_t1_kafka_consume_log
-rw-rw---- 1 mysql mysql 8889 Jun 18 13:55 rangeyear_t1_kafka_consume_log.frm
-rw-rw---- 1 mysql mysql 128 Jun 18 13:55 rangeyear_t1_kafka_consume_log.par
-rw-rw---- 1 mysql mysql 98304 Jun 18 11:27 rangeyear_t1_kafka_consume_log#P#p2012.ibd
-rw-rw---- 1 mysql mysql 98304 Jun 18 11:27 rangeyear_t1_kafka_consume_log#P#p2013.ibd
-rw-rw---- 1 mysql mysql 98304 Jun 18 11:27 rangeyear_t1_kafka_consume_log#P#p2014.ibd
例如:
CREATE TABLE users (
uid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL DEFAULT ,
email VARCHAR(30) NOT NULL DEFAULT
)
PARTITION BY RANGE (uid) (
PARTITION p0 VALUES LESS THAN (3000000)
DATA DIRECTORY = '/data0/data'
INDEX DIRECTORY = '/data1/idx',
PARTITION p1 VALUES LESS THAN (6000000)
DATA DIRECTORY = '/data2/data'
INDEX DIRECTORY = '/data3/idx',
PARTITION p2 VALUES LESS THAN MAXVALUE
DATA DIRECTORY = '/data6/data'
INDEX DIRECTORY = '/data7/idx'
);