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
This article shares the specific code of JavaScri...
This article introduces the installation of Windo...
Specific method: (Recommended tutorial: MySQL dat...
In fact many people will say “I’ve seen that table...
1. Under 800*600, if the width of the web page is...
Table of contents Preface Axios installation and ...
1. Effect display An astronaut watch face written...
js data types Basic data types: number, string, b...
/****************** * Kernel debugging technology...
Table of contents 1. Pull the Redis image 2. Crea...
Table of contents Create an image File Structure ...
Preface [root@localhost ~]# cat /etc/fstab # # /e...
This example takes the installation of Python 3.8...
1. Discover the problem © is the copyrigh...
Table of contents 1. Effect diagram (multiple col...