mysql表分区 笔记

CREATE TABLE `trecord` (
`tid` INT(11) NOT NULL AUTO_INCREMENT,
`task_id` VARCHAR(255) NULL DEFAULT NULL COMMENT '任务ID' COLLATE 'utf8_unicode_ci',
`taskCount` VARCHAR(255) NULL DEFAULT NULL COMMENT 'menupath id号' COLLATE 'utf8_unicode_ci',
`ttype` VARCHAR(50) NULL DEFAULT NULL COMMENT '类型:安卓 js pc' COLLATE 'utf8_unicode_ci',
`ip` VARCHAR(50) NULL DEFAULT NULL COMMENT 'ip' COLLATE 'utf8_unicode_ci',
`deviceID` VARCHAR(255) NULL DEFAULT NULL COMMENT '设备ID' COLLATE 'utf8_unicode_ci',
`createdate` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`tid`,`createdate`)
)
COLLATE='utf8_unicode_ci'
ENGINE=MyISAM
PARTITION BY RANGE (UNIX_TIMESTAMP(createdate)) (
    PARTITION p20180201 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-01')),
    PARTITION p20180202 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-02')),
    PARTITION p20180203 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-03')),
    PARTITION p20180204 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-04')),
    PARTITION p20180205 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-05')),
    PARTITION p20180206 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-06')),
    PARTITION p20180207 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-07')),
    PARTITION p20180208 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-08')),
    PARTITION p20180209 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-09')),
    PARTITION p20180210 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-10')),
    PARTITION p20180211 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-11')),
    PARTITION p20180212 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-12')),
    PARTITION p20180213 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-13')),
    PARTITION p20180214 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-14')),
    PARTITION p20180215 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-15')),
    PARTITION p20180216 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-16')),
    PARTITION p20180217 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-17')),
    PARTITION p20180218 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-18')),
    PARTITION p20180219 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-19')),
    PARTITION p20180220 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-20')),
    PARTITION p20180221 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-21')),
    PARTITION p20180222 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-22')),
    PARTITION p20180223 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-23')),
    PARTITION p20180224 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-24')),
    PARTITION p20180225 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-25')),
    PARTITION p20180226 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-26')),
    PARTITION p20180227 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-27')),
    PARTITION p20180228 VALUES LESS THAN (UNIX_TIMESTAMP('2018-02-28'))
);


SELECT * FROM information_schema.partitions WHERE table_name = 'trecord'##查询该表所有的表空间


alter table trecord drop partition p20180204;##删除指定表空间
 
ALTER TABLE trecord ADD PARTITION(PARTITION p20180301 VALUES LESS THAN (UNIX_TIMESTAMP('2018-03-01')))##新增trecord表空间

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值