我是否必须删除主键或重新加载 table 数据以在 MySQL InnoDB 中进行分区?

Do I have to drop the primary key or reload the table data for partitioning in MySQL InnoDB?

我必须按日期范围对一些表进行分区。我是否必须删除主数据或重新加载完整数据才能对这些表进行分区?

有些表确实包含超过 5000 万行。

alter table temp_table_test1
partition by range (unix_timestamp(created_at))
(
    partition p01 values less than (unix_timestamp('2015-02-01')),
    partition p02 values less than (unix_timestamp('2015-02-01')),
    partition p03 values less than (unix_timestamp('2015-02-01')),
    partition p04 values less than (unix_timestamp('2015-02-01')),
    partition p02 values less than (maxvalue)
);

这是我正在使用的脚本。

如果您还没有分区,则无需执行任何操作。根据 this thread 这将自动完成:

you can use ALTER TABLE to add partitioning to the table, keep in mind though that this will actually create the new partitioned table first, then copy over all the existing data, and finally drop the old unpartitioned table. So this operation may take a while and will temporarily use twice the disk space (which in the case of InnoDB is not given back to the operating system ...)