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
Preface The solution to the problem of not being ...
Text shadow text-shadow property effects: 1. Lowe...
FOUC is Flash of Unstyled Content, abbreviated as ...
Table of contents 1. MySQL replication process 2....
This article uses examples to describe the common...
For example: Copy code The code is as follows: <...
<br />I have always believed that Yahoo'...
Documentation: https://github.com/hilongjw/vue-la...
Effect (source code at the end): accomplish: 1. D...
Some common statements for viewing transactions a...
This article describes how to build a Nexus priva...
Table of contents The first The second Native Js ...
As a programmer who has just learned Tomcat, this...
1. Stop the mysqld.exe process first 2. Open cmd ...
Logo optimization: 1.The logo image should be as ...