Home > Database > Mysql Tutorial > 十三、mysql 分区之 RANGE && LIST_MySQL

十三、mysql 分区之 RANGE && LIST_MySQL

WBOY
Release: 2016-05-31 08:46:55
Original
1032 people have browsed it
1.RANGE 分区    创建实例:    CREATE TABLE EMP (        id int not null primary key auto_increment,        name char(25) not null default ''    )    PARTITION BY RANGE (id) ( 将字段id定义为分区的字段    PARTITION P0 VALUES LESS THAN (100), 99以下的id都归到p0分区    PARTITION P1 VALUES LESS THAN (200), 100-199    PARTITION P2 VALUES LESS THAN (300)  200-299    );    PS::因为默认会将0也算进去,所以P0实际可以存储0-99或-数    PS::要么不包含主键,如果要包含主键,那么分区字段也必须是主键    PS::mysql5.5以上支持日期进行分区,有什么作用,^_^,你可以想到的    2.List分区    创建实例:    CREATE TABLE LIST_EMP (        tid int not null PRIMARY key auto_increment,        tname char(20)    )    PARTITION BY LIST (tid) (        PARTITION P0 VALUES IN (1,3,5,7,9),          PARTITION P1 VALUES IN (2,4,6,8,10)    );    PS::通过上面的2种分区不难看出,RANGE分区是指定一个范围,而List分区是指定一个列表,在list中,只有指定的值才能存进去!    PS::个人觉得List分区更多可以用在分类上面    测试:    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');    insert into list_emp values (null,'Php');        insert into list_emp values (null,'Php');ERROR 1526 (HY000): Table has no partition for value 11        PS::第11条数据的时候报错,因为没有任何分区表包含了它
Copy after login

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template