MySQL:创建分区

时间:2018-09-26 16:01:25

标签: mysql

我有这样的表,我想根据类别ID进行分区。

buildPreBundle

所以我在mysql shell中写了

ALTER TABLE film_category

PARTITION BY RANGE(category_id) (

CREATE TABLE film_category (
   film_id SMALLINT UNSIGNED NOT NULL,
   category_id TINYINT UNSIGNED NOT NULL,
   last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE 
   CURRENT_TIMESTAMP,
   PRIMARY KEY (film_id, category_id),
   CONSTRAINT fk_film_category_film FOREIGN KEY (film_id) REFERENCES 
   film (film_id) ON DELETE RESTRICT ON UPDATE CASCADE,
   CONSTRAINT fk_film_category_category FOREIGN KEY (category_id) 
   REFERENCES category (category_id) ON DELETE RESTRICT ON UPDATE 
   CASCADE)ENGINE=InnoDB DEFAULT CHARSET=utf8;

); 但是我收到错误消息

PARTITION p1 VALUES ('1'),
PARTITION p2 VALUES ('2'), 
PARTITION p3 VALUES ('3'),  
PARTITION p4 VALUES ('4'),
PARTITION p5 VALUES ('5'),
PARTITION p6 VALUES ('6'),
PARTITION p7 VALUES ('7'),
PARTITION p8 VALUES ('8'),
PARTITION p9 VALUES ('9'),
PARTITION p10 VALUES ('10'),
PARTITION p11 VALUES ('11'),
PARTITION p12 VALUES ('12'),
PARTITION p13 VALUES ('13'),
PARTITION p14 VALUES ('14'),
PARTITION p15 VALUES ('15'),
PARTITION p16 VALUES ('16')

关于我犯了什么语法错误的任何线索?

1 个答案:

答案 0 :(得分:1)

您需要...

PARTITION p1 VALUES LESS THAN (2),    
PARTITION p2 VALUES LESS THAN (3),

等两件事情。

  1. VALUES LESS THAN是语法。

  2. 当您指的是实际数字('2')

  3. 时,请不要在数字(2)中加上数字