Create a partitioned table for an existing table and migrate the data to the new table. The table can be partitioned by time. However, this table is not updated in real time and there is one insert operation per day. How to operate @1 You can use ALTER TABLE to change the table to a partitioned table. This operation will create a partitioned table, automatically copy the data, and then delete the original table. Similar operations ALTER TABLE tbl_rtdata PARTITION BY RANGE (Month(fld_date)) ( PARTITION p_Apr VALUES LESS THAN (TO_DAYS('2012-05-01')), PARTITION p_May VALUES LESS THAN (TO_DAYS('2012-06-01')), PARTITION p_Dec VALUES LESS THAN MAXVALUE ); @2 Create a new partition table that is the same as the original table, then export the data from the original table and then import it into the new table. Operation processAdopt the second option. First create a partitioned table, then export the original table data, change the new table name to the original table name, then insert, and finally create a normal index. Create a partition table CREATE TABLE `apdailysts_p` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `ap_id` INT(11) NOT NULL, `mac` VARCHAR(17) NOT NULL, `liveinfo` LONGTEXT NOT NULL, `livetime` INT(11) NOT NULL, `stsdate` DATE NOT NULL, `lastmodified` DATETIME NOT NULL, PRIMARY KEY (`id`, `stsdate`) ) PARTITION BY RANGE COLUMNS(stsdate) ( PARTITION p0 VALUES LESS THAN ('2016-06-01'), PARTITION p1 VALUES LESS THAN ('2016-07-01'), PARTITION p2 VALUES LESS THAN ('2016-08-01'), PARTITION p3 VALUES LESS THAN ('2016-09-01'), PARTITION p4 VALUES LESS THAN ('2016-10-01'), PARTITION p5 VALUES LESS THAN ('2016-11-01'), PARTITION p6 VALUES LESS THAN ('2016-12-01'), PARTITION p7 VALUES LESS THAN ('2017-01-01'), PARTITION p8 VALUES LESS THAN ('2017-02-01'), PARTITION p9 VALUES LESS THAN ('2017-03-01'), PARTITION p10 VALUES LESS THAN ('2017-05-01'), PARTITION p11 VALUES LESS THAN ('2017-06-01'), PARTITION p12 VALUES LESS THAN ('2017-07-01'), PARTITION p13 VALUES LESS THAN ('2017-08-01'), PARTITION p14 VALUES LESS THAN ('2017-09-01'), PARTITION p15 VALUES LESS THAN MAXVALUE ); Exporting Data mysqldump -u dbname -p --no-create-info dbname apdailysts > apdailysts.sql Modify the table name, import data (it took 10 minutes to import 2 million data, a little over 8GB), test it and it is ok, then delete the original table. The test is working fine, and we will observe for 2 days. . – 10.16 This is the end of this article about how to partition an existing table in MySQL. For more information about how to partition an existing table in MySQL, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Use Firebug tool to debug the page on iPad
>>: A simple example of creating a thin line table in html
This article shares the specific code of jQuery t...
1. Percentage basis for element width/height/padd...
Preface Starting from MySQL 5.7.11, MySQL support...
Method 1: Use Google advanced search, for example...
Programs in Docker containers often need to acces...
Table of contents Preface Introduction to Bezier ...
One time we talked about the dice rolling game. A...
Mapping the mouse position or implementing drag e...
When using MYSQL, triggers are often used, but so...
1. First install the pagoda Installation requirem...
Recently, when I was writing a WeChat applet, the...
Preface In WeChat applet, you can use globalData ...
Kubernetes is the leader in the container orchest...
1. Create and run a container docker run -it --rm...
Table of contents 1. The direction of this in the...