当前位置:网站首页>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);
边栏推荐
- For the first time, why not choose "pure medium platform" for byte beating data platform
- Force deduction solution summary 398 random number index
- errno: -4078, code: ‘ECONNREFUSED‘, syscall: ‘connect‘, address: ‘127.0.0.1‘, port: 3306;postman报错
- Force deduction solution summary 824 goat Latin
- Force deduction solution summary 732- my schedule III
- Force deduction solution summary 942- increase / decrease string matching
- errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
- oracle之序列
- 微积分复习2
- Depth copy
猜你喜欢

Application of ard3m motor protector in coal industry

maya前臺渲染插件mel脚本工具

In 2022, don't you know the difference between arrow function and ordinary function?

Cupp dictionary generation tool (similar tools include crunch)

How to prevent electrical fire in shopping malls?

Demand and business model innovation - demand 6- stakeholder analysis and hard sampling

errno: -4078, code: ‘ECONNREFUSED‘, syscall: ‘connect‘, address: ‘127.0.0.1‘, port: 3306; Postman error

微积分复习2

I2C协议概述

Maya Front Office Rendering plug - in Mel script Tool
随机推荐
Abaqus中批量对节点施加集中力荷载
Proxy and reflection (II)
Cupp dictionary generation tool (similar tools include crunch)
Start stop script and distribution script of shell
errno: -4091, syscall: ‘listen‘, address: ‘::‘, port: 8000
Swiftyjson parsing local JSON files
Force deduction solution summary 732- my schedule III
SSH public key login failed with error: Sign_ and_ send_ pubkey: no mutual signature supported
Summary of force deduction method 417- Pacific Atlantic current problems
Force deduction solution summary 473 match to square
Transformation of geographical coordinates of wechat official account development
The road of global evolution of vivo global mall -- multilingual solution
One article to show you how to understand the harmonyos application on the shelves
Selection (045) - what is the output of the following code?
DDD的分层架构
cupp字典生成工具(同类工具还有crunch)
Calculus review 2
String number with special style
Force deduction solution summary 398 random number index
Selection (046) - what is the output of the following code?