当前位置:网站首页>A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
2022-04-23 14:14:00 【pureluckyfish】
One 、MYSQL Complete example of implementing sub table (5.7 edition )
1、 Build three identical sub tables user1、user2、user3
CREATE TABLE user1 (
id INT auto_increment NOT NULL,
name varchar(50) NULL,
sex INT DEFAULT 0 NOT NULL,
CONSTRAINT user1_pk PRIMARY KEY (id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE user2 (
id INT auto_increment NOT NULL,
name varchar(50) NULL,
sex INT DEFAULT 0 NOT NULL,
CONSTRAINT user1_pk PRIMARY KEY (id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
CREATE TABLE user3 (
id INT auto_increment NOT NULL,
name varchar(50) NULL,
sex INT DEFAULT 0 NOT NULL,
CONSTRAINT user1_pk PRIMARY KEY (id)
)ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
2、 Create another main table , The table structure is the same, but engine ENGINE=MRG_MyISAM; Addition, deletion, modification and query are all operations on this table , But the real data change is in each sub table
CREATE TABLE alluser (
id INT auto_increment NOT NULL,
name varchar(50) NULL,
sex INT DEFAULT 0 NOT null,
index(id)
)
ENGINE=MRG_MyISAM DEFAULT CHARSET=utf8
INSERT_METHOD=LAST UNION=(`user1`,`user2`,`user3`)
auto_increment=1 COMMENT=' A sub table implementation method ';
3、 verification : perform insert sentence , The query found that the data was stored in user3 in ( Why does data exist user3 Not user1 Well ? To look down )
insert into alluser(name,sex)values(' bald ',1);
select * from alluser;
delete from alluser where id=1;
select * from user1 ;
select * from user2 ;
select * from user3 ;
The article quoted :https://www.cnblogs.com/lucky-man/p/6207873.html If I have a user list user Yes 1100W Data , Now it's going to be broken into three tables user1 and user2 and user3,user1 Table storage 500w,user2 save 500w,user3 save 100w, All new user information will exist in the future user3 in . |
INSERT INTO user1(user1.id,user1.name,user1.sex)SELECT (user.id,user.name,user.sex)FROM user where user.id <= 5000000;
INSERT INTO user2(user2.id,user2.name,user2.sex)SELECT (user.id,user.name,user.sex)FROM user where user.id > 5000000 and user.id <= 10000000;
INSERT INTO user3(user3.id,user3.name,user3.sex)SELECT (user.id,user.name,user.sex)FROM user where user.id > 10000000;
In this way, I will succeed in putting one user surface , Divided into three tables , There is a problem at this time , In code sql What to do with the statement , It used to be a watch , Now it's three tables , The code has changed a lot , This brings a lot of workload to programmers , Is there a good way to solve this ? The way is to put the previous user Back up the table , Then delete , I created one of the above operations alluser surface , Just put this alluser Change the table name of the table to user That's it |
Two 、INSERT_METHOD There are three different ways
INSERT_METHOD=FIRST | Insert into the first table |
INSERT_METHOD=LAST | Insert into the last table |
INSERT_METHOD=NO Or default | Cannot perform insert operation |
3、 ... and 、MYSQL Brief description of various engines
show engines;-- Query all engines
English description | Engine applicable scenario | Create table statement | Data storage files |
InnoDB | 5.5 After version Mysql The default database for , The preferred engine for transactional databases , Support ACID Business , Support row level locking | ENGINE=InnoDB | .frm .ibd |
MyISAM | Has a higher insert , Query speed , But does not support Business | ENGINE=MyISAM | .frm .MYD .MYI |
MRG_MYISAM | There will be a certain number of MyISAM The watch is united into a whole , It's useful for very large-scale data storage | ENGINE=MRG_MYISAM | .frm .MRG |
MEMORY | All the data is put in the memory of the storage engine , Has extremely high insertion , Update and query efficiency . But it will occupy the memory space which is proportional to the amount of data . And its content will be in Mysql Lost on reboot | ENGINE=MEMORY | .frm |
ARCHIVE | Ideal for storing large amounts of independent , Data as a historical record . Because they are not often read .Archive With efficient insertion speed , But its support for query is relatively poor | ENGINE=ARCHIVE | .frm .ARZ |
mysql Data storage path
版权声明
本文为[pureluckyfish]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231406486556.html
边栏推荐
- Research on recyclerview details - Discussion and repair of recyclerview click dislocation
- Indoor and outdoor map switching (indoor three-point positioning based on ibeacons)
- Jmeter安装教程以及我遇到的问题的解决办法
- 帆软调用动态传参的方法,在标题中设置参数
- Wechat applet communicates with esp8266 based on UDP protocol
- 返回数组排序后下标
- RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
- mysql 5.1升级到5.66
- 百度图片识别自定义实现(替代AipOcr)
- 线程组ThreadGroup使用介绍+自定义线程工厂类实现ThreadFactory接口
猜你喜欢
关于密匙传递的安全性和数字签名
sql中出现一个变态问题
win10自带Groove音乐不能播放CUE和APE文件的一种曲线救国办法,自己创建aimppack插件包,AIMP安装DSP插件
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
Jmeter安装教程以及我遇到的问题的解决办法
Recyclerview advanced use (I) - simple implementation of sideslip deletion
HyperMotion云迁移完成阿里云专有云产品生态集成认证
云迁移的六大场景
帆软之单元格部分字体变颜色
VMware 15pro mounts the hard disk of the real computer in the deepin system
随机推荐
线程间控制之Semaphore使用介绍
DeepinV20安装Mariadb
1到100号的灯开关问题
不同时间类型的执行计划计算
Wechat applet communicates with low-power Bluetooth - sending data to hardware (III)
rsync+inotify远程同步
On September 8, the night before going to Songshan Lake
帆软中根据分类进行汇总
Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
On the multi-level certificate based on OpenSSL, the issuance and management of multi-level Ca, and two-way authentication
squid代理
使用itextpdf实现截取pdf文档第几页到第几页,进行分片
HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能
HyperMotion云迁移助力中国联通,青云完成某央企上云项目,加速该集团核心业务系统上云进程
Multiple inheritance virtual base exercises
RobotFramework 之 公共变量
Jmeter设置环境变量支持在任意终端目录输入jmeter直接启动
mysql 5.1升级到5.67
帆软调用动态传参的方法,在标题中设置参数
Subscription number development of wechat applet (message push)