Preface In a recent project, we need to save a large amount of data, and this data has an expiration date. In order to improve query efficiency and quickly delete expired data, we chose the MySQL partitioning mechanism. Partition the data by time. Partition Type
Partition Commands Create a partition CREATE TABLE `access_log` ( `id` int(11) NOT NULL AUTO_INCREMENT, `access_time` datetime NOT NULL, PRIMARY KEY (`id`,`access_time`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 /*!50100 PARTITION BY RANGE (to_days(access_time)) (PARTITION p1 VALUES LESS THAN (to_days(20190101)) ENGINE = InnoDB, PARTITION p2 VALUES LESS THAN (to_days(20190102)) ENGINE = InnoDB, PARTITION p3 VALUES LESS THAN (to_days(20190103)) ENGINE = InnoDB) */; After creation, you can see that each partition will correspond to an ibd file
Add a new partition alter table access_log add partition( partition p4 values less than (to_days('20190105')) ); Deleting a Partition alter table access_log drop partition p1; Split a partition alter table access_log reorganize partition p4 into( -> partition s0 values less than(to_days('20190104')), -> partition s1 values less than(to_days('20190105')) -> ); Merge partitions alter table access_log reorganize partition s0,s1 into ( partition p4 values less than (to_days('20190105')) ); Precautions
Frequently asked questions
alter table access_log partition by range(to_days(access_time))( partition p1 values less than (to_days('20191202')), partition p2 values less than (to_days('20191203')), partition po values less than (maxvalue) )
refer to
Summarize This is the end of this article about the basic introduction tutorial of MySQL partition table. For more relevant MySQL partition table content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: JavaScript Array Methods - Systematic Summary and Detailed Explanation
Syntax format: row_number() over(partition by gro...
Table of contents Overview Install Gulp.js Create...
Table of contents background: Nginx smooth upgrad...
Table of contents 1. What is a prototype? 1.1 Fun...
If someone asked you whether running EXPLAIN on a...
Using the <img> element with the default sr...
translate(-50%,-50%) attributes: Move it up and l...
Introduction I will write about the problem I saw...
After installing Docker, I encountered the x509 p...
<br />I just saw the newly revamped ChinaUI....
Classification of website experience 1. Sensory e...
1. Create a centos7.6 system and optimize the sys...
In order to enhance the ability to write JavaScri...
When we package the webpackjs file, we introduce ...
.NET SDK Download Link https://dotnet.microsoft.c...