• 以入库时间创建分区表


    以月份创建分区表

    CREATE TABLE IF NOT EXISTS `student`(
    	`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT `主键`,
    	`name` VARCHAR(50) NULL DEFAULT NULL COMMENT `姓名`,
    	`create_time` DATETIME NOT NULL COMMENT `入库时间`,
    	PRIMARY KEY (id,create_time)
    ) ENGINE=INNODB DEFAULT CHARSET=utf8
    PARTITION BY RANGE (MONTH(create_time))(
    PARTITION p1 VALUES LESS THAN(02),
    PARTITION p2 VALUES LESS THAN(03),
    PARTITION p3 VALUES LESS THAN(04),
    PARTITION p4 VALUES LESS THAN(05),
    PARTITION p5 VALUES LESS THAN(06),
    PARTITION p6 VALUES LESS THAN(07),
    PARTITION p7 VALUES LESS THAN(08),
    PARTITION p8 VALUES LESS THAN(09),
    PARTITION p9 VALUES LESS THAN(10),
    PARTITION p10 VALUES LESS THAN(11),
    PARTITION p11 VALUES LESS THAN(12),
    PARTITION p12 VALUES LESS THAN(13)
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20

    以天份创建分区表

    CREATE TABLE IF NOT EXISTS `student`(
    	`id` INT(11) NOT NULL AUTO_INCREMENT COMMENT `主键`,
    	`name` VARCHAR(50) NULL DEFAULT NULL COMMENT `姓名`,
    	`create_time` DATETIME NOT NULL COMMENT `入库时间`,
    	PRIMARY KEY (id,create_time)
    ) ENGINE=INNODB DEFAULT CHARSET=utf8
    PARTITION BY RANGE (DAY(create_time))(
    PARTITION p1 VALUES LESS THAN(02),
    PARTITION p2 VALUES LESS THAN(03),
    PARTITION p3 VALUES LESS THAN(04),
    PARTITION p4 VALUES LESS THAN(05),
    PARTITION p5 VALUES LESS THAN(06),
    PARTITION p6 VALUES LESS THAN(07),
    PARTITION p7 VALUES LESS THAN(08),
    PARTITION p8 VALUES LESS THAN(09),
    PARTITION p9 VALUES LESS THAN(10),
    PARTITION p10 VALUES LESS THAN(11),
    PARTITION p11 VALUES LESS THAN(12),
    PARTITION p12 VALUES LESS THAN(13),
    PARTITION p13 VALUES LESS THAN(14),
    PARTITION p14 VALUES LESS THAN(15),
    PARTITION p15 VALUES LESS THAN(16),
    PARTITION p16 VALUES LESS THAN(17),
    PARTITION p17 VALUES LESS THAN(18),
    PARTITION p18 VALUES LESS THAN(19),
    PARTITION p19 VALUES LESS THAN(20),
    PARTITION p20 VALUES LESS THAN(21),
    PARTITION p21 VALUES LESS THAN(22),
    PARTITION p22 VALUES LESS THAN(23),
    PARTITION p23 VALUES LESS THAN(24),
    PARTITION p24 VALUES LESS THAN(25),
    PARTITION p25 VALUES LESS THAN(26),
    PARTITION p26 VALUES LESS THAN(27),
    PARTITION p27 VALUES LESS THAN(28),
    PARTITION p28 VALUES LESS THAN(29),
    PARTITION p29 VALUES LESS THAN(30),
    PARTITION p30 VALUES LESS THAN(31),
    PARTITION p31 VALUES LESS THAN(32),
    );
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    查询分区表数据

    	SELECT * FROM `student` PARTITION(p3);
    
    • 1

    清空分区数据,不删除对应分区

    ALTER TABLE `student` TRUNCATE PARTITION(p5);
    
    • 1
  • 相关阅读:
    基于Java+SpringBoot+MyBatis+Vue前后端分离宠物领养设计与实现
    星起航跨境——万圣节产品不知道怎么选,这样选既安全又有效
    PhotoSweeper X mac版 v4.8.5 相似重复照片清理工具 兼容 M1/M2
    1011 World Cup Betting
    ubuntu 安装docker
    BSPHP 未授权访问 信息泄露
    如何搭建android源代码repo仓库
    ssh远程使用jupyter notebook
    PP-Tracking的ROS功能包
    vue 2个接口同步执行
  • 原文地址:https://blog.csdn.net/td725430/article/details/134446773