简体   繁体   English

MySQL改变了表分区语法

[英]MySQL alter table partitioning syntax

I tried to do table partitioning in MySQL by altering the table with the following code: 我试图通过使用以下代码更改表来在MySQL中进行表分区:

ALTER TABLE tt DROP PRIMARY KEY, ADD PRIMARY KEY(id, st);
ALTER TABLE tt ADD PARTITION BY LIST(st) (
    PARTITION p0 VALUES IN (20,10),
    PARTITION p1 VALUES IN (0,-10)
);

but got the following error: 但得到以下错误:

Mysql::Error: You have an error in your SQL syntax; Mysql ::错误:您的SQL语法中有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE tt ADD PARTITION (PARTITION p0 VALUES IN' at line 2: 查看与MySQL服务器版本对应的手册,以便在'ALTER TABLE tt ADD PARTITION(第2行的PARTITION p0 VALUES')附近使用正确的语法:

Can someone please let me what's wrong with the syntax? 有人可以告诉我语法有什么问题吗?

ALTER TABLE orders PARTITION BY LIST(st) (
          PARTITION p0 VALUES IN (20,10),
          PARTITION p1 VALUES IN (0,-10)
);

The ADD is extraneous - the syntax is essentially identical to the CREATE TABLE statement. ADD是无关的 - 语法基本上与CREATE TABLE语句相同。

Make sure you have a good, restorable backup before doing this. 在执行此操作之前,请确保您具有良好的可恢复备份。

Log: 日志:

mysql> create table orders (id int, st int, whatever varchar(10), primary key (id));
Query OK, 0 rows affected (0.06 sec)

mysql> ALTER TABLE orders DROP PRIMARY KEY, ADD PRIMARY KEY(id, st);
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE orders PARTITION BY LIST(st) (
    ->           PARTITION p0 VALUES IN (20,10),
    ->           PARTITION p1 VALUES IN (0,-10)
    -> );
Query OK, 0 rows affected (0.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM