当前位置:网站首页>MySQL partition table create delete modify view
MySQL partition table create delete modify view
2022-06-12 02:47:00 【Node. csn】
Partition table creation
The primary key of the partitioned table / All unique keys must contain partition keys
-- Create range partition table
CREATE TABLE `test_first` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`usr_id` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT ' The user no. ',
`remark` varchar(1024) COLLATE utf8_bin DEFAULT NULL COMMENT ' remarks ',
`rec_upd_ts` datetime(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT ' Record update time ',
`rec_crt_ts` datetime(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT ' Record creation time ',
`get_date` date NOT NULL COMMENT ' Partition field , Equity acquisition date ',
PRIMARY KEY (`id`,`get_date`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' Test partition table '
/*!50500 PARTITION BY RANGE COLUMNS(get_date) (PARTITION p_2021 VALUES LESS THAN ('2022-1-1') , PARTITION p_2022 VALUES LESS THAN ('2023-1-1') , PARTITION p_2023 VALUES LESS THAN ('2024-1-1') , PARTITION p_2024 VALUES LESS THAN ('2025-1-1') , PARTITION p_2025 VALUES LESS THAN ('2026-1-1') , PARTITION p_2026 VALUES LESS THAN ('2027-1-1') , PARTITION p_2027 VALUES LESS THAN ('2028-1-1') , PARTITION p_2028 VALUES LESS THAN ('2029-1-1') , PARTITION p_2029 VALUES LESS THAN ('2030-1-1') , PARTITION p_2030 VALUES LESS THAN ('2031-1-1') , PARTITION p_2031 VALUES LESS THAN ('2032-1-1') , PARTITION p_catchall VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) */;
explain :
Be careful :range The corresponding partition creation value must be a value or a comparable size type ).
range: The representative partition mode is range partition
less than: Say less than
Means less than a specific value , such as less than (2022-1-1), Then the value of the partition field is less than 2022-1-1 Of is in this partition , It doesn't contain 2022-1-1.
PARTITION p_catchall VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) Indicates that the rest of the range will fall to by default p_catchall Partition , Remove the statement if no default partition is required .
-- establish list Partition table
CREATE TABLE `test_second` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`usr_id` varchar(32) COLLATE utf8_bin DEFAULT NULL COMMENT ' The user no. ',
`remark` varchar(1024) COLLATE utf8_bin DEFAULT NULL COMMENT ' remarks ',
`rec_upd_ts` datetime(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT ' Record update time ',
`rec_crt_ts` datetime(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT ' Record creation time ',
`type` char(2) COLLATE utf8_bin NOT NULL COMMENT ' type ',
PRIMARY KEY (`id`,`type`)
) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT=' test list Partition table '
/*!50500 PARTITION BY LIST COLUMNS(type) (PARTITION p_1 values IN ('01','11') , PARTITION p_2 values IN ('02','12') , PARTITION p_3 values IN ('03','13') ) */;
explain :
LIST: Represents that the partition mode is the given value partition
in : When expressed as a given value
When type The value is ‘01’,‘11’ Store at p_1 Partition
New zoning
-- New range partition
alter TABLE `test_first` add PARTITION(
PARTITION p_2032 VALUES LESS THAN ('2033-1-1') ENGINE = InnoDB
);
-- newly added list Partition
alter TABLE `test_second` add PARTITION(
PARTITION p_4 values IN ('04','14') ENGINE = InnoDB
);
explain : Because partitions are incremented , If the default partition outside the range is executed when creating the partition , You cannot add a new partition , Because even without adding partitions , The data will also fall into the default partition . And if there is no default partition , The newly added partition should be added at the end
Delete partition
-- Delete the specified partition ( The data in the table will also be cleaned up )
alter table `test_first` drop PARTITION p_2029 ;
-- Delete multiple partitions ( The data in the table will also be cleaned up )
alter table `test_first` drop PARTITION p_2028,p_2029 ;
-- Delete all partitions of the table ( Delete only partitions , Do not delete data in the table )
alter table test_first remove partitioning;
Check the partition
-- Check whether it is a partitioned table
SHOW table STATUS;

-- View the partition information of the specified table
select
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
from information_schema.partitions where
table_schema = schema()
and table_name='test_first';

-- View the data in the specified partition
SELECT * FROM test_first PARTITION(p_2022);
边栏推荐
- Package a mobile APK app containing watch app - ticwear
- errno: -4078, code: ‘ECONNREFUSED‘, syscall: ‘connect‘, address: ‘127.0.0.1‘, port: 3306; Postman error
- Force deduction solution summary 388- longest absolute path of file
- maya前臺渲染插件mel脚本工具
- WPS table learning notes - highlight duplicate values
- 【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
- Function templatesfunction templates
- Force deduction solution summary 386 dictionary order
- Force deduction solution summary 473 match to square
- 1 minute to understand the essential difference between low code and zero code
猜你喜欢

I2C protocol overview

The road of global evolution of vivo global mall -- multilingual solution

Abaqus中批量对节点施加集中力荷载

Intel case

Drawcall, batches, setpasscall in unity3d

The program actively carries out telephone short message alarm, and customizes telephone, short message and nail alarm notifications

Ue4\ue5 touch screen touch event: single finger and double finger

Maya Front Office Rendering plug - in Mel script Tool

Maya foreground rendering plug-in Mel scripting tool

errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
随机推荐
Hypergraph tilted data is merged into root node and transferred to 3dfiles
余压监控系统在高层民用建筑的应用
小红的删数字
微积分复习2
Force deduction solution summary 1037- effective boomerang
【点云压缩】Sparse Tensor-based Point Cloud Attribute Compression
Introduction to architecture - who moved my cake
Graduation design of fire hydrant monitoring system --- thesis (add the most comprehensive hardware circuit design - > driver design - > Alibaba cloud Internet of things construction - > Android App D
Min25 sieve
The program actively carries out telephone short message alarm, and customizes telephone, short message and nail alarm notifications
Selection (045) - what is the output of the following code?
2022 Fujian Provincial Safety Officer C certificate (full-time safety officer) examination simulation 100 questions and answers
ZABBIX notes: 6.0 lts source code installation
跨域有哪些解决方法?
Research Report on Chinese psoriasis drug market evaluation and investment direction (2022 Edition)
Force deduction solution summary interview question 01.05 Edit once
Force deduction solution summary -04.06 Successor
ssh公钥登录失败报错:sign_and_send_pubkey: no mutual signature supported
Interpreting Julia's 2021: step by step towards the mainstream programming language
Android HTML5 page load cache optimization