表分区的大坑
MySQL Workbench建模,导出的sql脚本,无法执行。
[Err] 1178 - The storage engine for the table doesn’t support native partitioning
原因:
开始怀疑是反引号,后来发现不是这个问题。真正的原因是MyISAM存储引擎不支持RANGE表分区。 把 ENGINE = MyISAM 改成 ENGINE = InnoDB 又出现了另一个问题。 [Err] 1486 - Constant, random or timezone-dependent expressions in (sub)partitioning function are not allowed 原因是,TIMESTAMP类型不能使用to_days()函数做表分区。 把TIMESTAMP改成DATETIME,又出现另一个问题, [Err] 1503 - A PRIMARY KEY must include all columns in the table's partitioning function 原因是,分区字段必须加入主键,形成复合主键。 把 PRIMARY KEY (
id) 改成 PRIMARY KEY (
id,
logTime`))
测试通过,创建表分区成功。