我尝试通过使用以下代码更改表来在 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)
);
但出现以下错误:
Mysql::Error: You have an error in your SQL syntax; 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:
有人可以告诉我语法有什么问题吗?
最佳答案
ALTER TABLE orders PARTITION BY LIST(st) (
PARTITION p0 VALUES IN (20,10),
PARTITION p1 VALUES IN (0,-10)
);
ADD 是无关的 - 语法本质上与 CREATE TABLE 语句相同。
在执行此操作之前,请确保您有良好的、可恢复的备份。
日志:
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
关于MySQL 更改表分区语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8690502/