mysql> show variables like '%partition%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| have_partitioning | YES |
+-------------------+-------+
1 row in set (0.00 sec)
MySQL分区类型:
● RANGE 分区
● LIST 分区
● HASH 分区
● KEY 分区
不论创建何种类型的分区,如果表存在主键或者唯一性索引时,分区列必须是唯一性索引的一个组成部分。
mysql> create table t( col1 int not null,
-> col2 int not null,
-> col3 int not null,
-> col4 int not null,
-> unique key (col1,col2)
-> )
-> partition by hash(col3)
-> partitions 4;
ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
mysql> create table t( col1 int not null,
-> col2 int not null,
-> col3 int not null,
-> col4 int not null,
-> unique key (col1,col2)
-> )
-> partition by hash(col2)
-> partitions 4;
Query OK, 0 rows affected (0.08 sec)