一.创建订单表orders :
CREATE TABLE orders (
order_id INT NOT NULL,
order_date DATE NOT NULL,
amount DECIMAL(10, 2) NOT NULL
) PARTITION BY RANGE (YEAR(order_date)) (
PARTITION p0 VALUES LESS THAN (1991),
PARTITION p1 VALUES LESS THAN (1992),
PARTITION p2 VALUES LESS THAN (1993),
PARTITION p3 VALUES LESS THAN (1994),
PARTITION pmax VALUES LESS THAN MAXVALUE
);
测试看看 INSERT INTO orders(order_id, order_date, amount) VALUES(1,'1992-01-01',10.1)
二.更改表为按月分区存储
ALTER TABLE orders
PARTITION BY RANGE (MONTH(order_date)) (
PARTITION p0 VALUES LESS THAN (2),
PARTITION p1 VALUES LESS THAN (3),
PARTITION p2 VALUES LESS THAN (4),
PARTITION p3 VALUES LESS THAN (5),
PARTITION pmax VALUES LESS THAN MAXVALUE
);