当前位置:网站首页>Implementation of partition table of existing data table by MySQL
Implementation of partition table of existing data table by MySQL
2022-04-23 11:06:00 【liming89】
Source of the article : Learn through http://www.bdgxy.com/
Create a partition table for an existing table , And migrate the data to the new table , You can partition by time , Then the table is not updated in real time , Insert once a day .
There's plenty of time , But there are other applications on the server , Using smaller resources is the main way .
Mode of operation
@1 have access to ALTER TABLE To change the table into a partitioned table , This operation will create a partition table , Then automatically perform data processing copy Then delete the original table ,
Guess that the server resource consumption is relatively large .
Similar operation
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 partition table that is the same as the original table , Then export the data from the original table , Then pour in the new watch .
( The primary key of the original table is only id, And my partition field is stsdate, Here, the primary key should be changed to id,stsdate Combined the primary key , Partition table requires partition fields to be primary keys or part of primary keys )
The operation process
Adopt the second scheme . First create a partition table , Then export the original table data , The new table name is changed to the original table name , Then insert , Finally, establish a general index .
Create partition tables
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
);
Derived data
mysqldump -u dbname -p --no-create-info dbname apdailysts > apdailysts.sql
Modify the name of the table , Import data (10 The import is finished in minutes ,200w, 8g A little more data ), Under test ok, Delete the original table .
The test can be used normally , Call it a day , Observe 2 God ..
– 10.16
Through these two days of observation , The query speed of the page has changed from unable to open to the speed of seconds , This optimization is established .
This is about MySQL This is the end of the article on the implementation of partitioning the existing table of the data table , More about MySQL There is already a table to partition. Please search the rookie tutorial www.piaodoo.com Previous articles or continue to browse the relevant articles below. I hope you can support rookie tutorials in the future www.piaodoo.com!
版权声明
本文为[liming89]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231102124311.html
边栏推荐
- Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
- vm设置静态虚拟机
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- Mysql排序的特性详情
- The courses bought at a high price are open! PHPer data sharing
- web三大组件(Servlet,Filter,Listener)
- MBA-day5數學-應用題-工程問題
- Gets the current time in character format
- Structure of C language (Advanced)
- Prevent SQL injection in web projects
猜你喜欢
Visual common drawing (III) area map
Mysql8.0安装指南
How to quickly download vscode
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
Visual common drawing (V) scatter diagram
ConstraintLayout布局
Constraintlayout layout
精彩回顾|「源」来如此 第六期 - 开源经济与产业投资
Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
STM32接电机驱动,杜邦线供电,然后反烧问题
随机推荐
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
学习 Go 语言 0x08:《Go 语言之旅》中 练习使用 error
解决 『SunCertPathBuilderException:unable to find valid certification path to requested target』 问题
@valid,@Validated 的学习笔记
Difference between pregnancy box and delivery box
mysql中整数数据类型tinyint详解
Google Earth engine (GEE) - scale up the original image (taking Hainan as an example)
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
Esp32 learning - add folder to project
Latex usage
第六站神京门户-------手机号码的转换
Structure of C language (Advanced)
26. 删除有序数组中的重复项
Mysql排序的特性详情
Learning notes 7-depth neural network optimization
The courses bought at a high price are open! PHPer data sharing
C语言之结构体(进阶篇)
活动进行时! 点击链接加入直播间参与“AI真的能节能吗?”的讨论吧!
Hikvision face to face summary
语雀文档编辑器将开源:始于但不止于Markdown