Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql partition #15

Open
clms2 opened this issue Aug 24, 2018 · 0 comments
Open

mysql partition #15

clms2 opened this issue Aug 24, 2018 · 0 comments

Comments

@clms2
Copy link
Owner

clms2 commented Aug 24, 2018

需注意:原表需要有且仅有一个作为区分分区字段的键(分区字段需包含在唯一/主键索引里):
  • alter table order_subscribe add primark key(id,created_at)
  • 在现有表上进行分区:
ALTER TABLE order_subscribe PARTITION BY RANGE COLUMNS(created_at)
(   
PARTITION p1 VALUES LESS THAN ('2018-02-01 00:00:00'),
PARTITION p2 VALUES LESS THAN ('2018-03-01 00:00:00'),
PARTITION p3 VALUES LESS THAN ('2018-04-01 00:00:00'),
PARTITION p4 VALUES LESS THAN ('2018-05-01 00:00:00'),
PARTITION p5 VALUES LESS THAN ('2018-06-01 00:00:00'),
PARTITION p6 VALUES LESS THAN ('2018-07-01 00:00:00'),
PARTITION p7 VALUES LESS THAN ('2018-08-01 00:00:00'),
PARTITION p8 VALUES LESS THAN ('2018-09-01 00:00:00'),
PARTITION p9 VALUES LESS THAN ('2018-10-01 00:00:00'),
PARTITION p10 VALUES LESS THAN MAXVALUE
);
  • 在现有分区上进行再次分区:
ALTER TABLE  order_subscribe REORGANIZE PARTITION p0 INTO (
	PARTITION p1 VALUES LESS THAN ('2018-05-01 00:00:00'),
	PARTITION p2 VALUES LESS THAN ('2018-06-01 00:00:00')
);
  • 有大量数据删除时优化分区:ALTER TABLE order_subscribe OPTIMIZE PARTITION
  • 又想还原回原来的单表形式:ALTER TABLE order_subscribe REMOVE PARTITIONING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant