当前位置:网站首页>Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts
Use Navicat to compare data differences and structure differences of multi environment databases, and automatic DML and DDL scripts
2022-06-25 09:10:00 【ZWZhangYu】
List of articles
explain
It is used in development projects today navicat When the synchronization tool accidentally sees data synchronization and structure synchronization, it is a little curious , So I simply used it , After use, I feel it is very suitable for the current needs ;
【1】 Comparison of database tables in different environments , And automatically generate differences DDL sentence
【2】 The difference of data records in different environments , And automatic generation DML sentence
【 The data transfer 】 I believe that developers are familiar with and often use , And for 【 Data synchronization 】【 Structure synchronization 】 There was no contact before , The data synchronization mainly compares the data differences of the corresponding tables between the two data , Structure synchronization mainly compares the difference of data tables between two databases and the generation of SQL Script .
Structure synchronization
Prepare two databases , Then create a data table with the same table name in the two databases , The upper table is one more than the lower one address Field .
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`create_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `t_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`age` int(11) DEFAULT NULL,
`create_time` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
choice 【 Tools 】【 Structure contrast 】, choice t_user The results are as follows , You can see the difference intuitively through the following display
Click on 【 Deployment scripts 】 You can see the differences that the tool helps us generate SQL, Very convenient
Data synchronization
Based on the table structure above , Execute the above generated DDL Statement to keep the data tables on both sides consistent , Then add the following test data
【 Source library 】
INSERT INTO `t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (1, ' Zhang San ', 25, ' Hefei, Anhui ', '2022-06-22 15:29:16');
INSERT INTO `t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (2, ' Li Si ', 25, ' Hefei ', '2022-06-22 15:29:54');
INSERT INTO `t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (3, ' Wang Wu ', 25, ' Hefei ', '2022-06-22 15:29:54');
【 Target library 】
INSERT INTO `t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (1, ' Zhang San ', 25, ' Hefei, Anhui ', '2022-06-22 15:29:16');
INSERT INTO `t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (3, ' Wang Wu ', 26, ' Shanghai ', '2022-06-22 15:29:54');
Click on 【 Tools 】【 Data synchronization 】, Select source library and target library , The following figure is the result of this comparison .
【A】 The area shows the records of tables with different data after comparison , It shows different number of records and the same number, etc .
【B】 Here, you can choose to display only different data , Same data , All the data, etc , The results are shown in C Area , Will be marked with different colors .
【C】 The actual comparison results are shown , From the above figure, you can see the relationship between the two libraries ID by 1 The data records are the same , One more table on the left ID by 2 The record of , The two tables ID by 3 The recorded data of are different
【D】 Deploy , Clicking deploy will generate a different SQL, As shown in the example above , From source library to target library , There will be a new ID by 2 The record of , And update the ID by 3 The record of
Generated DML as follows :
SET FOREIGN_KEY_CHECKS = 0;
INSERT INTO `test`.`t_user`(`id`, `name`, `age`, `address`, `create_time`) VALUES (2, ' Li Si ', 25, ' Hefei ', '2022-06-22 15:29:54');
UPDATE `test`.`t_user` SET `name` = ' Wang Wu ', `age` = 25, `address` = ' Hefei ', `create_time` = '2022-06-22 15:29:54' WHERE `id` = 3;
SET FOREIGN_KEY_CHECKS = 1;
among :SET FOREIGN_KEY_CHECKS effect : In execution sql Script time , To prevent foreign keys from being affected .
Summary
【1】 This time, we simply tested the functions of data synchronization and structure synchronization , These two functions are also inadvertently touched during work , After understanding, I really feel that it will be helpful for future project development .
【2】 For which the data structure is synchronized , During version testing or large version upgrade , If the upgrade script is not retained , This tool can be used to quickly generate relevant DDL sentence . If you have prepared an upgrade script , You can also use this tool to compare the source library with the target library , This ensures that there will be no missing items when upgrading , Make a guarantee .
【3】 The data synchronization function can be applied to some basic tables 、 Configuration table 、 Dictionaries, tables, etc , If someone changes some data during development but fails to submit it in time , It will lead to different environments . Besides , Changes to the data structure can generally be submitted in a timely manner , But for temporary modification of some configuration data , Basic data may be omitted , Then you can compare the differences through this tool , And automatically generate differences SQL.
【4】 After touching this function , I also found some similar products , such as Liquibase、dbForge Data Compare、 And some open source platforms . The overall function is similar ,Navicat The functions provided here are very convenient and powerful , Most importantly, there are no other costs , As the database connection tool currently used by the project team , You can directly connect to various environment databases without additional configuration , And it is stable and easy to use .
边栏推荐
- 获取扫码的客户端是微信还是支付宝
- Lvs-dr mode multi segment case
- Flitter gets the height of the top status bar
- Openfoam: bottom layer
- Unknown table 'column of MySQL_ STATISTICS‘ in information_ schema (1109)
- Atguigu---18-component
- compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
- Notes on key words in the original English work biography of jobs (II) [chapter one]
- 华泰证券在上面开户安全吗?靠谱吗?
- 证券开户风险大吗,安全靠谱吗?
猜你喜欢
Numpy numpy中的meshgrid()函数
Explanation of assertions in JMeter
自定义注解之编译时注解(RetentionPolicy.CLASS)
从别人库里拷贝的游戏如何再自己的库里显示
Close a thread
Unity发布webGL的时候JsonConvert.SerializeObject()转换失败
Matplotlib plt Axis() usage
Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?
Voiceprint Technology (VI): other applications of voiceprint Technology
C language: bubble sort
随机推荐
Flutter multilingual intl: ^0.17.0 cannot be imported
某次比赛wp
On the underlying index principle of MySQL
Matplotlib plt Axis() usage
Notes on key words in the original English work biography of jobs (VI) [chapter three]
WebGL谷歌提示内存不够(RuntimeError:memory access out of bounds,火狐提示索引超出界限(RuntimeError:index out of bounds)
【期末复习笔记】数字逻辑
Jmeter接口测试,关联接口实现步骤(token)
Jmeter中的断言使用讲解
Voiceprint Technology (VI): other applications of voiceprint Technology
How safe is the new bond
《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
通过客户经理的开户二维码开股票账户安全吗?
《乔布斯传》英文原著重点词汇笔记(五)【 chapter three 】
对常用I/O模型进行比较说明
将jar包注册为服务,实现开机自动启动
【MYSQL】索引的理解和使用
首期Techo Day腾讯技术开放日,628等你!
matplotlib matplotlib中决策边界绘制函数plot_decision_boundary和plt.contourf函数详解
annotation lib 和 processor lib如何引用