mysql利用TO_DAYS()函数创建分区

创建分区,为tg_sr_data表的字段logTime创建分区,TO_DAYS返回天级别的,下面的LESS THAN (737877)中的737877是1970到现在的天数时间。

ALTER TABLE tg_sr_data PARTITION by RANGE(TO_DAYS(logTime))
(
PARTITION p20200327 VALUES LESS THAN (737877) ENGINE = InnoDB,
 PARTITION p20200328 VALUES LESS THAN (737878) ENGINE = InnoDB,
 PARTITION p20200329 VALUES LESS THAN (737879) ENGINE = InnoDB,
 PARTITION p20200330 VALUES LESS THAN (737880) ENGINE = InnoDB,
 PARTITION p20200331 VALUES LESS THAN (737881) ENGINE = InnoDB,
 PARTITION p20200401 VALUES LESS THAN (737882) ENGINE = InnoDB,
 PARTITION p20200402 VALUES LESS THAN (737883) ENGINE = InnoDB,
 PARTITION p20200403 VALUES LESS THAN (737884) ENGINE = InnoDB,
 PARTITION p20200404 VALUES LESS THAN (737885) ENGINE = InnoDB,
 PARTITION p20200405 VALUES LESS THAN (737886) ENGINE = InnoDB,
 PARTITION p20200406 VALUES LESS THAN (737887) ENGINE = InnoDB,
 PARTITION p20200407 VALUES LESS THAN (737888) ENGINE = InnoDB,
 PARTITION p20200408 VALUES LESS THAN (737889) ENGINE = InnoDB,
 PARTITION p20200409 VALUES LESS THAN (737890) ENGINE = InnoDB,
 PARTITION p20200410 VALUES LESS THAN (737891) ENGINE = InnoDB,
 PARTITION p20200411 VALUES LESS THAN (737892) ENGINE = InnoDB,
 PARTITION p20200412 VALUES LESS THAN (737893) ENGINE = InnoDB,
PARTITION p20200413 VALUES LESS THAN (737894) ENGINE = InnoDB,
 PARTITION p20200414 VALUES LESS THAN (737895) ENGINE = InnoDB,
 PARTITION p20200415 VALUES LESS THAN (737896) ENGINE = InnoDB,
 PARTITION p20200416 VALUES LESS THAN (737897) ENGINE = InnoDB,
 PARTITION p20200417 VALUES LESS THAN (737898) ENGINE = InnoDB,
 PARTITION p20200418 VALUES LESS THAN (737899) ENGINE = InnoDB,
 PARTITION p20200419 VALUES LESS THAN (737900) ENGINE = InnoDB,
 PARTITION p20200420 VALUES LESS THAN (737901) ENGINE = InnoDB,
 PARTITION p20200421 VALUES LESS THAN (737902) ENGINE = InnoDB,
 PARTITION p20200422 VALUES LESS THAN (737903) ENGINE = InnoDB,
 PARTITION p20200423 VALUES LESS THAN (737904) ENGINE = InnoDB,
 PARTITION p20200424 VALUES LESS THAN (737905) ENGINE = InnoDB,
 PARTITION p20200425 VALUES LESS THAN (737906) ENGINE = InnoDB,
 PARTITION p20200426 VALUES LESS THAN (737907) ENGINE = InnoDB,
 PARTITION p20200427 VALUES LESS THAN (737908) ENGINE = InnoDB,
 PARTITION p20200428 VALUES LESS THAN (737909) ENGINE = InnoDB,
 PARTITION p20200429 VALUES LESS THAN (737910) ENGINE = InnoDB,
 PARTITION p20200430 VALUES LESS THAN (737911) ENGINE = InnoDB,
 PARTITION p20200501 VALUES LESS THAN (737912) ENGINE = InnoDB,
 PARTITION p20200502 VALUES LESS THAN (737913) ENGINE = InnoDB,
 PARTITION p20200503 VALUES LESS THAN (737914) ENGINE = InnoDB,
 PARTITION p20200504 VALUES LESS THAN (737915) ENGINE = InnoDB,
 PARTITION p20200505 VALUES LESS THAN (737916) ENGINE = InnoDB,
 PARTITION p20200506 VALUES LESS THAN (737917) ENGINE = InnoDB,
 PARTITION p20200507 VALUES LESS THAN (737918) ENGINE = InnoDB,
 PARTITION p20200508 VALUES LESS THAN (737919) ENGINE = InnoDB,
 PARTITION p20200509 VALUES LESS THAN (737920) ENGINE = InnoDB,
 PARTITION p20200510 VALUES LESS THAN (737921) ENGINE = InnoDB,
 PARTITION p20200511 VALUES LESS THAN (737922) ENGINE = InnoDB,
 PARTITION p20200512 VALUES LESS THAN (737923) ENGINE = InnoDB,
 PARTITION p20200513 VALUES LESS THAN (737924) ENGINE = InnoDB,
 PARTITION p20200514 VALUES LESS THAN (737925) ENGINE = InnoDB,
 PARTITION p20200515 VALUES LESS THAN (737926) ENGINE = InnoDB,
 PARTITION p20200516 VALUES LESS THAN (737927) ENGINE = InnoDB,
 PARTITION p20200517 VALUES LESS THAN (737928) ENGINE = InnoDB,
 PARTITION p20200518 VALUES LESS THAN (737929) ENGINE = InnoDB,
 PARTITION p20200519 VALUES LESS THAN (737930) ENGINE = InnoDB,
 PARTITION p20200520 VALUES LESS THAN (737931) ENGINE = InnoDB,
 PARTITION p20200521 VALUES LESS THAN (737932) ENGINE = InnoDB,
 PARTITION p20200522 VALUES LESS THAN (737933) ENGINE = InnoDB,
 PARTITION p20200523 VALUES LESS THAN (737934) ENGINE = InnoDB,
 PARTITION p20200524 VALUES LESS THAN (737935) ENGINE = InnoDB,
 PARTITION p20200525 VALUES LESS THAN (737936) ENGINE = InnoDB,
 PARTITION p20200526 VALUES LESS THAN (737937) ENGINE = InnoDB,
 PARTITION p20200527 VALUES LESS THAN (737938) ENGINE = InnoDB,
 PARTITION p20200528 VALUES LESS THAN (737939) ENGINE = InnoDB,
 PARTITION p20200529 VALUES LESS THAN (737940) ENGINE = InnoDB,
 PARTITION p20200530 VALUES LESS THAN (737941) ENGINE = InnoDB,
 PARTITION p20200531 VALUES LESS THAN (737942) ENGINE = InnoDB,
 PARTITION p20200601 VALUES LESS THAN (737943) ENGINE = InnoDB,
 PARTITION p20200602 VALUES LESS THAN (737944) ENGINE = InnoDB,
 PARTITION p20200603 VALUES LESS THAN (737945) ENGINE = InnoDB,
 PARTITION p20200604 VALUES LESS THAN (737946) ENGINE = InnoDB,
 PARTITION p20200605 VALUES LESS THAN (737947) ENGINE = InnoDB,
 PARTITION p20200606 VALUES LESS THAN (737948) ENGINE = InnoDB,
 PARTITION p20200607 VALUES LESS THAN (737949) ENGINE = InnoDB,
 PARTITION p20200608 VALUES LESS THAN (737950) ENGINE = InnoDB,
 PARTITION p20200609 VALUES LESS THAN (737951) ENGINE = InnoDB,
 PARTITION p20200610 VALUES LESS THAN (737952) ENGINE = InnoDB,
 PARTITION p20200611 VALUES LESS THAN (737953) ENGINE = InnoDB,
 PARTITION p20200612 VALUES LESS THAN (737954) ENGINE = InnoDB,
 PARTITION p20200613 VALUES LESS THAN (737955) ENGINE = InnoDB,
 PARTITION p20200614 VALUES LESS THAN (737956) ENGINE = InnoDB,
 PARTITION p20200615 VALUES LESS THAN (737957) ENGINE = InnoDB,
 PARTITION p20200616 VALUES LESS THAN (737958) ENGINE = InnoDB,
 PARTITION p20200617 VALUES LESS THAN (737959) ENGINE = InnoDB,
 PARTITION p20200618 VALUES LESS THAN (737960) ENGINE = InnoDB,
 PARTITION p20200619 VALUES LESS THAN (737961) ENGINE = InnoDB,
 PARTITION p20200620 VALUES LESS THAN (737962) ENGINE = InnoDB,
 PARTITION p20200621 VALUES LESS THAN (737963) ENGINE = InnoDB,
 PARTITION p20200622 VALUES LESS THAN (737964) ENGINE = InnoDB,
 PARTITION p20200623 VALUES LESS THAN (737965) ENGINE = InnoDB,
 PARTITION p20200624 VALUES LESS THAN (737966) ENGINE = InnoDB,
 PARTITION p20200625 VALUES LESS THAN (737967) ENGINE = InnoDB,
 PARTITION p20200626 VALUES LESS THAN (737968) ENGINE = InnoDB,
 PARTITION p20200627 VALUES LESS THAN (737969) ENGINE = InnoDB,
 PARTITION p20200628 VALUES LESS THAN (737970) ENGINE = InnoDB,
 PARTITION p20200629 VALUES LESS THAN (737971) ENGINE = InnoDB,
 PARTITION p20200630 VALUES LESS THAN (737972) ENGINE = InnoDB,
 PARTITION p20200701 VALUES LESS THAN (737973) ENGINE = InnoDB,
 PARTITION p20200702 VALUES LESS THAN (737974) ENGINE = InnoDB,
 PARTITION p20200703 VALUES LESS THAN (737975) ENGINE = InnoDB,
 PARTITION p20200704 VALUES LESS THAN (737976) ENGINE = InnoDB,
 PARTITION p20200705 VALUES LESS THAN (737977) ENGINE = InnoDB,
 PARTITION p20200706 VALUES LESS THAN (737978) ENGINE = InnoDB,
 PARTITION p20200707 VALUES LESS THAN (737979) ENGINE = InnoDB,
 PARTITION p20200708 VALUES LESS THAN (737980) ENGINE = InnoDB,
 PARTITION p20200709 VALUES LESS THAN (737981) ENGINE = InnoDB,
 PARTITION p20200710 VALUES LESS THAN (737982) ENGINE = InnoDB,
 PARTITION p20200711 VALUES LESS THAN (737983) ENGINE = InnoDB,
 PARTITION p20200712 VALUES LESS THAN (737984) ENGINE = InnoDB,
 PARTITION p20200713 VALUES LESS THAN (737985) ENGINE = InnoDB,
 PARTITION p20200714 VALUES LESS THAN (737986) ENGINE = InnoDB,
 PARTITION p20200715 VALUES LESS THAN (737987) ENGINE = InnoDB,
 PARTITION p20200716 VALUES LESS THAN (737988) ENGINE = InnoDB,
 PARTITION p20200717 VALUES LESS THAN (737989) ENGINE = InnoDB,
 PARTITION p20200718 VALUES LESS THAN (737990) ENGINE = InnoDB,
 PARTITION p20200719 VALUES LESS THAN (737991) ENGINE = InnoDB,
 PARTITION p20200720 VALUES LESS THAN (737992) ENGINE = InnoDB,
 PARTITION p20200721 VALUES LESS THAN (737993) ENGINE = InnoDB,
 PARTITION p20200722 VALUES LESS THAN (737994) ENGINE = InnoDB,
 PARTITION p20200723 VALUES LESS THAN (737995) ENGINE = InnoDB,
 PARTITION p20200724 VALUES LESS THAN (737996) ENGINE = InnoDB,
 PARTITION p20200725 VALUES LESS THAN (737997) ENGINE = InnoDB,
 PARTITION p20200726 VALUES LESS THAN (737998) ENGINE = InnoDB,
 PARTITION p20200727 VALUES LESS THAN (737999) ENGINE = InnoDB,
 PARTITION p20200728 VALUES LESS THAN (738000) ENGINE = InnoDB,
 PARTITION p20200729 VALUES LESS THAN (738001) ENGINE = InnoDB

)
 

你可能感兴趣的:(数据库)