当前位置:网站首页>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 .
边栏推荐
- The meshgrid() function in numpy
- Matplotlib simple logistic regression visualization
- QSS buttons of different styles
- C program termination problem clr20r3 solution
- 手机办理长城证券开户靠谱安全吗?
- 对常用I/O模型进行比较说明
- Cazy eight trigrams maze of Chang'an campaign
- nodejs 使用Express框架demo
- C language: find all integers that can divide y and are odd numbers, and put them in the array indicated by B in the order from small to large
- Socket programming -- poll model
猜你喜欢

Webgl Google prompt memory out of bounds (runtimeerror:memory access out of bounds, Firefox prompt index out of bounds)

Jmeter接口测试,关联接口实现步骤(token)

【无标题】**数据库课设:三天完成学生信息管理系统**

¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!

matplotlib matplotlib中plt.axis()用法

Format analysis and explanation of wav file

Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?

【期末复习笔记】数字逻辑

compiling stm32f4xx_ it. c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).

高速缓冲存储器Cache的映射方式
随机推荐
IC研发常用英文术语缩写
获取扫码的客户端是微信还是支付宝
1、 Construction of single neural network
annotation lib 和 processor lib如何引用
C#启动程序传递参数丢失双引号,如何解决?
2、 Training fashion_ MNIST dataset
matplotlib matplotlib中决策边界绘制函数plot_decision_boundary和plt.contourf函数详解
3大问题!Redis缓存异常及处理方案总结
Notes on key vocabulary of the original English work biography of jobs (I) [introduction]
《乔布斯传》英文原著重点词汇笔记(五)【 chapter three 】
atguigu----18-组件
自定义注解之编译时注解(RetentionPolicy.CLASS)
Is it safe to buy stocks and open accounts through the account QR code of the account manager? Want to open an account for stock trading
使用Navicat对比多环境数据库数据差异和结构差异,以及自动DML和DDL脚本
Is the client that gets the scanning code wechat or Alipay
cazy长安战役八卦迷宫
QSS buttons of different styles
sklearn 高维数据集制作make_circles 和 make_moons
compiling stm32f4xx_it.c... “.\Objects\BH-F407.axf“ - 42 Error(s), 1 Warning(s).
Matplotlib decision boundary drawing function plot in Matplotlib_ decision_ Boundary and plt Detailed explanation of contour function