当前位置:网站首页>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
边栏推荐
- Introduction to neo4j authoritative guide, recommended by Qiu Bojun, Zhou Hongxiang, Hu Xiaofeng, Zhou Tao and other celebrities
- Software testers, how to mention bugs?
- About the three commonly used auxiliary classes of JUC
- 学习 Go 语言 0x05:《Go 语言之旅》中映射(map)的练习题代码
- Visual common drawing (V) scatter diagram
- Typora operation skill description (I) md
- Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
- Go interface usage
- Constraintlayout layout
- 妊娠箱和分娩箱的区别
猜你喜欢

Promise details

26. Delete duplicates in ordered array

MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了

Solutions to common problems in visualization (IX) background color

Typora operation skill description (I) md

VM set up static virtual machine

The courses bought at a high price are open! PHPer data sharing

About the three commonly used auxiliary classes of JUC

第六站神京门户-------手机号码的转换

Microsoft Access database using PHP PDO ODBC sample
随机推荐
Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
Pytorch implementation of transformer
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
Manjaro installation and configuration (vscode, wechat, beautification, input method)
SVN的使用:
如何使用JDBC CallableStatement.wasNull()方法调用来查看最后一个OUT参数的值是否为 SQL NULL
我的创作纪念日
Google Earth Engine(GEE)——将原始影像进行升尺度计算(以海南市为例)
数据库管理软件SQLPro for SQLite for Mac 2022.30
The difference between restful and soap
MBA-day5数学-应用题-工程问题
Promise详解
软件测试人员,如何优秀的提Bug?
MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题
MIT:用无监督为世界上每个像素都打上标签!人类:再也不用为1小时视频花800个小时了
ConstraintLayout布局
采用百度飞桨EasyDL完成指定目标识别
ffmpeg命令行常用参数
学习 Go 语言 0x07:《Go 语言之旅》中 Stringer 练习题代码
Excel · VBA array bubble sorting function