当前位置:网站首页>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
边栏推荐
- MBA-day5數學-應用題-工程問題
- Chapter 1 of technical Xiaobai (express yourself)
- @Valid, @ validated learning notes
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- mysql中整数数据类型tinyint详解
- Solutions to common problems in visualization (VIII) solutions to problems in shared drawing area
- Common parameters of ffmpeg command line
- VIM usage
- Mysql系列SQL查询语句书写顺序及执行顺序详解
- CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
猜你喜欢

Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)

关于JUC三大常用辅助类

Mysql8.0安装指南

Excel · VBA custom function to obtain multiple cell values

More reliable model art than deep learning

VIM + ctags + cscope development environment construction guide

VM set up static virtual machine

《Neo4j权威指南》简介,求伯君、周鸿袆、胡晓峰、周涛等大咖隆重推荐

语雀文档编辑器将开源:始于但不止于Markdown

Visual common drawing (IV) histogram
随机推荐
Xdotool key Wizard
The difference between restful and soap
Excel·VBA数组冒泡排序函数
Mysql排序的特性详情
vm设置静态虚拟机
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
Cumcm 2021 - B: préparation d'oléfines C4 par couplage éthanol (2)
Source insight 4.0 FAQs
UDP basic learning
About the three commonly used auxiliary classes of JUC
Three web components (servlet, filter, listener)
JDBC – PreparedStatement – 如何设置 Null 值?
Oracle connectivity test gadget
How to quickly query 10 million pieces of data in MySQL
How to use JDBC callablestatement The wasnull () method is called to check whether the value of the last out parameter is SQL null
PlatoFarm推出正式版游戏经济模型的特点分析
Jupyter Lab 十大高生产力插件
Prevent SQL injection in web projects
Typora operation skill description (I) md
Detailed explanation of typora Grammar (I)