当前位置:网站首页>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 .
边栏推荐
- How can games copied from other people's libraries be displayed in their own libraries
- Are the top ten securities companies at great risk of opening accounts and safe and reliable?
- Unity--Configurable Joint——简单教程,带你入门可配置关节
- 声纹技术(二):音频信号处理基础
- In Section 5 of bramble pie project practice, Nokia 5110 LCD is used to display Hello World
- Notes on key words in the original English work biography of jobs (III) [chapter one]
- 请问在手机上开户股票,还是去证券公司开户安全?
- WebGL谷歌提示内存不够(RuntimeError:memory access out of bounds,火狐提示索引超出界限(RuntimeError:index out of bounds)
- SQL高级
- C program termination problem clr20r3 solution
猜你喜欢
![[opencv] - Discrete Fourier transform](/img/03/10ce3d7c5d99ead944b2cae8d0cec0.png)
[opencv] - Discrete Fourier transform

浅谈Mysql底层索引原理

C#程序终止问题CLR20R3解决方法

从别人库里拷贝的游戏如何再自己的库里显示

【OpenCV】—输入输出XML和YAML文件

4、 Convolution neural networks

matplotlib matplotlib中plt.grid()

3 big questions! Redis cache exceptions and handling scheme summary

Make a skylearn high-dimensional dataset_ Circles and make_ moons

Matplotlib plt grid()
随机推荐
wav文件(波形文件)格式分析与详解
请问在手机上开户股票,还是去证券公司开户安全?
《乔布斯传》英文原著重点词汇笔记(二)【 chapter one】
Analysis on the bottom calling process of micro service calling component ribbon
《乔布斯传》英文原著重点词汇笔记(五)【 chapter three 】
Le labyrinthe des huit diagrammes de la bataille de cazy Chang'an
将jar包注册为服务,实现开机自动启动
三、自动终止训练
【OpenCV】—输入输出XML和YAML文件
Atguigu---18-component
Atguigu---01-scaffold
关掉一个线程
The first techo day Tencent technology open day, 628 waiting for you!
备战2022年金九银十必问的1000道Android面试题及答案整理,彻底解决面试的烦恼
Level 6 easy to mix words
Cazy eight trigrams maze of Chang'an campaign
Atguigu---17-life cycle
nodejs 使用Express框架demo
Voiceprint Technology (VII): the future of voiceprint Technology
Format analysis and explanation of wav file