关于mysql创建表分区,让id自增长、加上主键的话就报错,取消就能创建成功的问题!求大神帮助下!!!

2025-04-30 00:15:59
推荐回答(1个)
回答1:

MySQL主键的限制,每一个分区表中的公式中的列,必须在主键/unique key 中包括
MYSQL的官方文档里是这么说明的
18.5.1. Partitioning Keys, Primary Keys, and Unique Keys
This section discusses the relationship of partitioning keys with primary keys and unique keys. The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

In other words,every unique key on the table must use every columnin the table's partitioning expression. (This also includes the table's primary key, since it is by definition a unique key. This particular case is discussed later in this section.) For example, each of the following table creation statements is invalid:

解决办法是创建复合主键,将id和你的分区字段创建复合主键..