Data synchronization method, device, equipment and readable storage medium

By dynamically identifying the field types of database tables and generating SQL statements based on the full amount of data, the time-consuming problem of database synchronization is solved, and fast and efficient data synchronization and consistent updates are achieved.

CN113987075BActive Publication Date: 2025-09-26GUANGZHOU PINWEI SOFTWARE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111349973.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-15
Publication Date
2025-09-26
Estimated Expiration
2041-11-15

AI Technical Summary

Technical Problem

In the prior art, data synchronization of database systems is time-consuming and inefficient, and it is difficult to ensure data consistency, especially in multiple environments.

Method used

By dynamically identifying the field types and full data of the target database table, generating SQL statements for inserting data, and executing them in the database to be synchronized, fast synchronization of database tables is achieved.

Benefits of technology

It reduces the workload of manual script writing, improves the synchronization efficiency during database system upgrades or backups, and ensures data consistency in multiple environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113987075B_ABST
    Figure CN113987075B_ABST
Patent Text Reader

Abstract

The present application discloses a data synchronization method, apparatus, device and readable storage medium. The present application can pre-configure a benchmark database IP set and a benchmark database set. After obtaining the target benchmark database IP corresponding to the database table that the user requests to synchronize, the field type of the database table that the user requests to synchronize can be dynamically identified in the target database instance in the target benchmark database corresponding to the target benchmark database IP, and the full amount of data of the database table that the user requests to synchronize under the target database instance can be read, and an SQL statement for inserting data corresponding to each database table that the user requests to synchronize can be generated to achieve the purpose of synchronizing the database table that the user requests to synchronize. The user does not need to write backup or initialization scripts for the database tables that need to be synchronized one by one, which saves the time of synchronizing the database tables when the database system is upgraded or backed up, and improves the efficiency of data update.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and more specifically, to a data synchronization method, apparatus, device, and readable storage medium. Background Art

[0002] Currently, almost all internet computer applications require the use of databases. A database system is comprised of a database and its management software. Developed to meet data processing needs, a database system is an ideal data processing system. It is also a software system that provides data for operational storage, maintenance, and application systems. It comprises storage media, processing objects, and management systems. However, in the long-term operation of a database system, data maintenance is often costly and inefficient.

[0003] For example, during routine application system testing, multiple functional test environments may be used, corresponding to multiple database systems. Due to various factors, the business data in each environment's database may contain errors, redundancies, incompleteness, and inconsistencies after prolonged field operation. This can lead to inconsistent testing, impacting test efficiency and results. A common solution is to back up each table from a baseline database, write corresponding database scripts, and restore them to the databases in the other environments. Furthermore, during application system upgrades, initialization updates to the corresponding database tables are required. A common approach for updating database tables is for professional technicians to write initialization scripts, which testers then execute in the test environments. Scripts are often written to batch-process all initialization scripts. Whether backing up table data or updating database tables during system upgrades, manual backup and restore scripts are required to synchronize database tables. Multiple environments require multiple manual data synchronization operations, which is time-consuming, inconvenient for maintaining and upgrading system data, and difficult to ensure consistent updates across multiple environments.

[0004] Therefore, there is an urgent need to provide a method that can quickly synchronize data to solve the problem of time-consuming database synchronization. Summary of the Invention

[0005] In view of this, the present application provides a data synchronization method, apparatus, device and readable storage medium for solving the problem of time-consuming database table synchronization.

[0006] A data synchronization method, comprising:

[0007] Get the target benchmark database IP address corresponding to the database table that the user requests to synchronize;

[0008] Determining a target benchmark database corresponding to the target benchmark database IP from a pre-configured benchmark database set;

[0009] Determine, from the target reference database, a target database instance corresponding to the database table synchronized with the user request;

[0010] Dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance;

[0011] Generate an SQL statement for inserting data corresponding to each database table requested by the user for synchronization based on the field type and the full amount of data;

[0012] The SQL statement for inserting data is executed in the database to be synchronized, so as to synchronize the database table requested by the user to the database to be synchronized.

[0013] Preferably, before generating the SQL statement for inserting data corresponding to each database table requested to be synchronized by the user based on the field type and the full amount of data, the method further includes:

[0014] Determine whether the full amount of data in each database table requested for synchronization by the user is complete;

[0015] If yes, then executing the step of generating an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user based on the field type and the full amount of data;

[0016] If not, traverse the database tables that the user requests to synchronize in the corresponding target database instance, re-read the unread row data in the database tables that the user requests to synchronize, until all reading is completed, re-identify the field type of the read database table, and execute the step of generating the SQL statement for insert data corresponding to each database table that the user requests to synchronize based on the field type and the full amount of data.

[0017] Preferably, after executing the SQL statement for inserting data in the database to be synchronized to synchronize the database table requested by the user to the database to be synchronized, the method further includes:

[0018] Determine whether the database table requested by the user is synchronized successfully;

[0019] If yes, output the database table after successful synchronization;

[0020] If not, the database tables that failed to synchronize are stored in a preset synchronization failure database, and the reason for the synchronization failure of each database table that failed to synchronize is recorded.

[0021] Preferably, after storing the database tables that failed to synchronize in a preset synchronization failure database and recording the reason for the synchronization failure of each database table that failed to synchronize, the method further includes:

[0022] Output the database tables that failed to synchronize and the reasons for synchronization failure, so that users can repair the data;

[0023] After confirming that the database table that failed to be synchronized in the benchmark database has been repaired, the process returns to the step of dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full data of the database table requested to be synchronized by the user under the target database instance.

[0024] A data synchronization device, comprising:

[0025] An IP acquisition unit is used to obtain the target reference database IP corresponding to the database table that the user requests to synchronize;

[0026] A database acquisition unit, configured to determine a target reference database corresponding to the target reference database IP from a pre-configured reference database set;

[0027] an instance acquisition unit, configured to determine, from the target reference database, a target database instance corresponding to a database table synchronized with a user request;

[0028] A database table processing unit, configured to dynamically identify the field type of the database table requested to be synchronized by the user from the target database instance, and read the full amount of data of the database table requested to be synchronized by the user under the target database instance;

[0029] An SQL statement generating unit, configured to generate, based on the field type and the full amount of data, an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user;

[0030] The synchronization unit is used to execute the SQL statement of inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0031] Preferably, the data synchronization device further includes:

[0032] A first judgment unit is used to judge whether the full amount of data of each database table requested to be synchronized by the user is complete; if so, execute the SQL statement generation unit;

[0033] If not, traverse the database table that the user requests to synchronize in the corresponding target database instance, and re-execute the database processing unit to read the unread row data in the database table that the user requests to synchronize, until all reading is completed, identify the field type of the read database table, and execute the SQL statement generation unit after executing the database table processing unit.

[0034] Preferably, the data synchronization device further includes:

[0035] A second judgment unit is used to judge whether the database table requested to be synchronized by the user is synchronized successfully after the synchronization unit is executed;

[0036] a first output unit, configured to output the database table after successful synchronization when the execution result of the second judgment unit is yes;

[0037] The recording unit is configured to store the database tables that failed to be synchronized in a preset synchronization failure database when the execution result of the second judgment unit is no, and record the reason for the failure of each synchronization failure database table.

[0038] Preferably, the data synchronization device further includes:

[0039] A second output unit is configured to output the database table that failed to be synchronized and the reason for the synchronization failure after the recording unit is executed, so as to facilitate the user to perform data repair;

[0040] The confirmation unit is used to confirm whether the database table that failed to be synchronized in the reference database has been repaired, and if so, return to execute the database table processing unit.

[0041] A data synchronization device includes a memory and a processor;

[0042] The memory is used to store programs;

[0043] The processor is used to execute the program to implement each step of any of the data synchronization methods described above.

[0044] A readable storage medium having a computer program stored thereon, characterized in that when the computer program is executed by a processor, the steps of any of the data synchronization methods described above are implemented.

[0045] It can be seen from the above technical solution that the data synchronization method of the present application can pre-configure the benchmark database IP set and the benchmark database set so that the user can select the target benchmark database corresponding to the target benchmark database IP to synchronize data during human-computer interaction. After pre-configuring the benchmark database IP set and the benchmark database set, the target benchmark database IP corresponding to the database table that the user requests to synchronize can be obtained. After obtaining the target benchmark database IP, the target benchmark database corresponding to the target benchmark database IP can be determined from the pre-configured benchmark database set. After determining the target benchmark database, the target database instance corresponding to the database table that the user requests to synchronize can be determined from the target benchmark database. After determining the target database instance, the field type of the database table that the user requests to synchronize can be dynamically identified from the target database instance, and the full amount of data of the database table that the user requests to synchronize under the target database instance can be read. After identifying the field type and reading the full amount of data, the SQL statement for inserting data corresponding to each database table that the user requests to synchronize can be generated based on the field type and the full amount of data. After the SQL statement is generated, the SQL statement for inserting data may be executed in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0046] This application can achieve the purpose of synchronizing the database tables requested by the user by dynamically identifying the field types of the database tables that the user requests to synchronize, reading the full amount of data of the database tables that the user requests to synchronize under the target database instance, and generating SQL statements for inserting data corresponding to each database table that the user requests to synchronize. The user does not need to write backup or initialization scripts for each database table to be synchronized. The user only needs to pre-configure the benchmark database IP set and benchmark database set so that the user can select the target benchmark database corresponding to the target benchmark database IP to synchronize data during human-computer interaction. This saves time in synchronizing database tables when upgrading or backing up the database system and improves the efficiency of data updates. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without any creative work.

[0048] Figure 1-Figure 4 This is a flowchart of a method for implementing data synchronization according to an example embodiment of the present application;

[0049] Figure 5A schematic diagram of the structure of a data synchronization device according to an embodiment of the present application;

[0050] Figure 6 This is a hardware structure block diagram of a data synchronization device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0051] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0052] In the era of big data, with the ever-increasing pace of data updates and iterations, database system upgrades or backups are commonplace in everyday life. These upgrades and backups require synchronization or backup of system data. A common solution is to back up each table in a baseline database, write the corresponding database scripts, and then restore the data to a database in a separate environment. This approach has several drawbacks: First, each synchronization or backup requires the development of specialized backup and recovery scripts, resulting in low efficiency. Second, if a database system has multiple execution environments, multiple manual synchronization or backup operations are required.

[0053] To address this, new update methods were developed. When application system upgrades involved initializing and updating the corresponding database tables, professional technicians wrote initialization scripts, which testers then executed in the test environment to synchronize or back up data. Later, to improve efficiency, testers developed a method for batch-processing all initialization scripts by writing scripts. However, this new update method still struggled to ensure consistent basic data across multiple execution environments.

[0054] Therefore, a method for quickly synchronizing data is urgently needed.

[0055] In order to solve this problem, the present application provides a data synchronization method, which can be used to solve the problem of time-consuming data synchronization.

[0056] The method can be applied to any device that can implement the data synchronization method. Optionally, the device that can implement the data synchronization method can be a terminal with data processing capabilities, such as a tablet computer, a mobile phone, and a digital television.

[0057] The following combination Figure 1 , introduces the process of the data synchronization method provided in the embodiment of the present application, which may include the following steps:

[0058] Step S101: Obtain the target reference database IP corresponding to the database table that the user requests to synchronize.

[0059] Specifically, the target reference database IP corresponding to the database table requested to be synchronized by the user can be obtained, so that during human-computer interaction, the user can centrally confirm the target reference database corresponding to the target reference database IP according to pre-configured reference databases.

[0060] Step S102: determining a target reference database corresponding to the target reference database IP from a pre-configured reference database set.

[0061] Specifically, after obtaining the target reference database IP corresponding to the database table requested to be synchronized by the user, the target reference database corresponding to the target reference database IP can be determined from the pre-configured reference database set, so that the target database instance corresponding to the database table requested to be synchronized by the user can be determined in the target reference database.

[0062] Step S103: determining a target database instance corresponding to the database table requested to be synchronized by the user from the target reference database.

[0063] Specifically, after determining the target reference database corresponding to the target reference database IP in the preconfigured reference database set, the target database instance corresponding to the database table requested to be synchronized by the user can be determined from the target reference database, so as to determine the database table requested to be synchronized by the user in the target database instance.

[0064] Step S104 : dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance.

[0065] Specifically, after the target reference database identifies the target database instance corresponding to the database table requested for synchronization by the user, it can dynamically identify the field types of the database table requested for synchronization from the target database instance and read the full data of the database table requested for synchronization from the target database instance. This allows the SQL statement for inserting data corresponding to each database table requested for synchronization to be generated.

[0066] Step S105 : Based on the field type and the full amount of data, generate an SQL statement for inserting data corresponding to each database table that the user requests to synchronize.

[0067] Specifically, after identifying the field type of the database table that the user requests to synchronize and reading the full data of the database table that the user requests to synchronize, an SQL statement for inserting data corresponding to each database table that the user requests to synchronize can be generated based on the field type and the full data.

[0068] SQL is an ANSI-standard computer language that can be used to access and operate database systems. SQL statements can be used to retrieve and update data in a database. SQL is a standard language that works with database programs such as MS Access, DB2, Informix, MS SQL Server, Oracle, MySQL, Sybase, and other database systems. The SQL statement for inserting data is a type of SQL statement that can be used to insert data into a target database. Therefore, executing the SQL statement for inserting data can be used to insert data into the database to be synchronized, thereby achieving data synchronization.

[0069] Step S106: executing the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0070] Specifically, after generating an SQL statement for inserting data corresponding to each database table requested for synchronization by the user, the SQL statement for inserting data may be executed in the database to be synchronized to synchronize the database table requested for synchronization by the user to the database to be synchronized.

[0071] As can be seen from the above technical solution, this application can achieve the purpose of synchronizing the database tables requested by the user by dynamically identifying the field types of the database tables requested to be synchronized by the user, reading the full amount of data of the database tables requested to be synchronized by the user under the target database instance, and generating SQL statements for inserting data corresponding to each database table requested to be synchronized by the user. The user does not need to write backup or initialization scripts for the database tables to be synchronized one by one. It only needs to pre-configure the benchmark database IP set and benchmark database set so that the user can select the target benchmark database corresponding to the target benchmark database IP to synchronize data during human-computer interaction. This saves the time of synchronizing database tables when upgrading or backing up the database system and improves the efficiency of data updates.

[0072] Taking into account that when reading the database table requested by the user to be synchronized under the target database instance, a reading failure may occur, resulting in the data of the database table requested by the user to be synchronized under the target database instance being read not being the full data of the data table, therefore, in the above step S105, the embodiment of the present application generates the SQL statement for inserting data corresponding to each database table requested by the user to be synchronized based on the field type and the full data, and then adds a process to determine whether the full data of each database table requested to be synchronized by the user is complete.

[0073] Based on this, we will then combine Figure 2 , another implementation method of the data synchronization method is introduced. The process may include the following steps:

[0074] Step S101: Obtain the target reference database IP corresponding to the database table that the user requests to synchronize.

[0075] Step S102: determining a target reference database corresponding to the target reference database IP from a pre-configured reference database set.

[0076] Step S103: determining a target database instance corresponding to the database table requested to be synchronized by the user from the target reference database.

[0077] Step S104 : dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance.

[0078] Step S107: Determine whether the full amount of data in each database table requested to be synchronized by the user is complete. If so, step S105 may be executed; if not, step S108 may be executed.

[0079] Specifically, after dynamically identifying the field types of the database tables requested for synchronization from the target database instance and reading the full data of the database tables requested for synchronization under the target database instance, it is possible to determine whether the full data of each database table requested for synchronization is complete, thereby ensuring that the full data of each database table requested for synchronization is complete. If so, step S105 can be executed; if not, step S108 can be executed.

[0080] For example, the full data of each database table requested for synchronization by the user can be compared with the full data of each database table requested for synchronization in the target database instance to determine whether the full data of each database table requested for synchronization by the user is consistent. If the two are consistent, it means that the full data of each database table requested for synchronization by the user is complete. If the two are inconsistent, it means that the full data of each database table requested for synchronization by the user is incomplete.

[0081] In addition, the MD5 value of each database table requested to be synchronized by the user in the target database instance and the MD5 value of each database table requested to be synchronized by the user in the target database instance can be calculated respectively. Based on the two MD5 values ​​corresponding to each database table requested to be synchronized by the user, it can be determined whether the full data of each database table requested to be synchronized by the user is consistent with the full data of each database table requested to be synchronized by the user in the target database instance. If the two MD5 values ​​corresponding to each database table requested to be synchronized by the user are the same, it means that the full data of each database table requested to be synchronized by the user under the target database instance has been read. Step S105 can be further executed. If not, it means that the full data of each database table requested to be synchronized by the user under the target database instance has not been read, and the full data of the database table corresponding to the user requested to be synchronized under the target database instance needs to be re-read. Then, step S108 can be executed to complete the data reading work of each data table requested to be synchronized by the user under the target database instance.

[0082] Step S108, traverse the database table requested to be synchronized by the user in the corresponding target database instance, re-read the unread row data in the database table requested to be synchronized by the user, until all the data is read, re-identify the field type of the read database table, and execute step S105.

[0083] Specifically, after calculating the two MD5 values ​​corresponding to each database table requested by the user to be synchronized, if the two MD5 values ​​corresponding to each database table requested by the user to be synchronized are not the same, the corresponding database tables in the data tables requested to be synchronized by the user in the target database instance are traversed, and the unread row data in the database tables requested to be synchronized by the user are re-read until all are read. After the unread database tables are read, the field types of the read database tables can be re-identified. After identifying the field types of the read data tables, step S105 can be executed to generate an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user.

[0084] Step S105 : Based on the field type and the full amount of data, generate an SQL statement for inserting data corresponding to each database table that the user requests to synchronize.

[0085] Step S106: executing the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0086] The details of steps S101 to S106 can be found in the above description and will not be repeated here.

[0087] As can be seen from the above scheme, the embodiment of the present application can determine whether the read database table data is the full data of each database table requested to be synchronized by the user in the target database instance before generating the SQL statement for inserting data corresponding to each database table requested to be synchronized by the user based on the field type and the full data. If the read database table data is not the full data of each database table requested to be synchronized by the user in the target database instance, the data of the database table that has not been read can be re-read to ensure that the read database table data is the full data of the database table requested to be synchronized by the user.

[0088] It is understandable that in actual application, database table synchronization may sometimes fail. Therefore, in the above step S106, the embodiment of the present application executes the SQL statement of the insert data in the database to be synchronized to synchronize the database table requested by the user to be synchronized to the database to be synchronized. Then, a process of recording the database table that failed to be synchronized and the reason for the synchronization failure can be added.

[0089] Next, based on Figure 3 , another implementation method of the data synchronization method is introduced. The process may include the following steps:

[0090] Step S101: Obtain the target reference database IP corresponding to the database table that the user requests to synchronize.

[0091] Step S102: determining a target reference database corresponding to the target reference database IP from a pre-configured reference database set.

[0092] Step S103: determining a target database instance corresponding to the database table requested to be synchronized by the user from the target reference database.

[0093] Step S104 : dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance.

[0094] Step S107: Determine whether the full amount of data in each database table requested to be synchronized by the user is complete. If so, step S105 may be executed; if not, step S108 may be executed.

[0095] Step S108, traverse the database table requested to be synchronized by the user in the corresponding target database instance, re-read the unread row data in the database table requested to be synchronized by the user, until all the data is read, re-identify the field type of the read database table, and execute step S105.

[0096] Step S105 : Based on the field type and the full amount of data, generate an SQL statement for inserting data corresponding to each database table that the user requests to synchronize.

[0097] Step S106: executing the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0098] The details of steps S101 to S108 can be found in the above description and will not be repeated here.

[0099] Step S109 , determining whether the database table requested to be synchronized by the user is synchronized successfully, if so, executing step S110 , if not, executing step S111 .

[0100] Specifically, after executing the SQL statement for inserting data in the database to be synchronized, it can be determined whether the database table requested to be synchronized by the user is synchronized successfully.

[0101] For example, the full amount of data in the synchronized database table can be compared with the full amount of data in the database table requested by the user in the target database instance to determine whether the synchronization of the database table requested by the user is successful.

[0102] In addition, the MD5 value of the database table of the database to be synchronized can be calculated and compared with the MD5 value of the database table of the synchronized database and the corresponding database table in the target database instance. If the two are the same, it means that the database table in the synchronized database is consistent with the database table in the target database instance, indicating that the database table requested by the user has been synchronized successfully, and step S110 is executed. If the two are inconsistent, it means that there is a database table that failed to be synchronized, and step S110 is executed.

[0103] Step S110: Output the database table after successful synchronization.

[0104] Specifically, when the data table requested to be synchronized by the user is successfully synchronized, the successfully synchronized database table can be output to facilitate subsequent maintenance by the user.

[0105] Step S111: storing the database tables that failed to be synchronized in a preset synchronization failure database, and recording the reason for the synchronization failure of each database table that failed to be synchronized.

[0106] Specifically, if there are database tables that fail to synchronize, the database tables that fail to synchronize can be stored in a preset synchronization failure database, and the reason for the synchronization failure of each database table that fails to synchronize is recorded for the user to perform data repair.

[0107] It can be seen from the above technical solution that the embodiment of the present application can further determine whether the database table requested by the user to be synchronized is synchronized successfully after synchronizing the database table requested by the user. If the synchronization fails, the database table that failed to be synchronized can be stored in a preset synchronization failure database, and the reason for the synchronization failure of each database table that failed to be synchronized can be recorded for the user to repair the data.

[0108] It can be considered that when the database table requested to be synchronized by the user fails to be synchronized, in order to complete the synchronization purpose, the database table that failed to be synchronized needs to be synchronized again. To achieve this goal, in the above step S111, the embodiment of the present application stores the database table that failed to be synchronized in a preset synchronization failure database and records the reason for the synchronization failure of each database table that failed to be synchronized. Then, the process of outputting the database table that failed to be synchronized and the reason for the synchronization failure can be added to facilitate the user to perform data repair.

[0109] Next, combine Figure 4 , another implementation method of the data synchronization method is introduced. The process may include the following steps:

[0110] Step S101: Obtain the target reference database IP corresponding to the database table that the user requests to synchronize.

[0111] Step S102: determining a target reference database corresponding to the target reference database IP from a pre-configured reference database set.

[0112] Step S103: determining a target database instance corresponding to the database table requested to be synchronized by the user from the target reference database.

[0113] Step S104 : dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance.

[0114] Step S107: Determine whether the full amount of data in each database table requested to be synchronized by the user is complete. If so, step S105 may be executed; if not, step S108 may be executed.

[0115] Step S108, traverse the database table requested to be synchronized by the user in the corresponding target database instance, re-read the unread row data in the database table requested to be synchronized by the user, until all the data is read, re-identify the field type of the read database table, and execute step S105.

[0116] Step S105 : Based on the field type and the full amount of data, generate an SQL statement for inserting data corresponding to each database table that the user requests to synchronize.

[0117] Step S106: executing the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0118] Step S109 , determining whether the database table requested to be synchronized by the user is synchronized successfully, if so, executing step S110 , if not, executing step S111 .

[0119] The details of steps S101 to S109 can be found in the above description and will not be repeated here.

[0120] Step S110: Output the database table after successful synchronization.

[0121] Specifically, when the data table requested to be synchronized by the user is successfully synchronized, the successfully synchronized database table can be output to facilitate subsequent maintenance by the user.

[0122] Step S111: storing the database tables that failed to be synchronized in a preset synchronization failure database, and recording the reason for the synchronization failure of each database table that failed to be synchronized.

[0123] Step S112: Output the database table that failed to synchronize and the reason for the synchronization failure, so that the user can perform data repair.

[0124] Specifically, after storing the database tables that failed synchronization in a pre-set synchronization failure database and recording the reasons for each failed synchronization database table, it is indicated that the data in the corresponding database table in the target database instance may contain non-standard or incomplete data. Therefore, the database tables that failed synchronization and the reasons for the synchronization failure can be output, allowing the user to return to the target database instance to repair the data tables based on the failed synchronization database tables and the reasons for the synchronization failure.

[0125] Step S113 , confirming whether the database table that failed to be centrally synchronized with the reference database has been repaired. If it is confirmed that the database table that failed to be centrally synchronized with the reference database has been repaired, the process returns to step S104 .

[0126] Specifically, after confirming that the database tables that failed synchronization in the baseline database set have been repaired, the process returns to the steps of dynamically identifying the field types of the database tables requested for synchronization from the target database instance and reading the full data of the database tables requested for synchronization from the target database instance, so as to resynchronize the database tables that failed synchronization.

[0127] It can be seen from the above technical solution that the embodiment of the present application can output the database table that failed to synchronize and the reason for the synchronization failure, so that the user can return to the target database instance to repair the corresponding database table based on the database table that failed to synchronize and the reason for the synchronization failure, so as to synchronize the database table requested by the user.

[0128] Considering that when the user updates or backs up system data, if the user does not specifically request to synchronize any database table in the benchmark database, the default synchronization can be set to all database tables in all database instances of the benchmark database corresponding to the target benchmark database IP requested by the user.

[0129] The following introduces the data synchronization device provided in the embodiment of the present application. The data synchronization device described below and the data synchronization method described above can refer to each other.

[0130] See also Figure 5 , Figure 5 This is a structural diagram of a data synchronization device disclosed in an embodiment of the present application.

[0131] like Figure 5 As shown, the data synchronization device may include:

[0132] The IP acquisition unit 101 is used to acquire the target reference database IP corresponding to the database table that the user requests to synchronize;

[0133] The database acquisition unit 102 is configured to determine a target reference database corresponding to the target reference database IP from a pre-configured reference database set;

[0134] An instance acquisition unit 103 is configured to determine, from the target reference database, a target database instance corresponding to a database table synchronized with a user request;

[0135] The database table processing unit 104 is configured to dynamically identify the field type of the database table requested to be synchronized by the user from the target database instance, and read the full amount of data of the database table requested to be synchronized by the user under the target database instance;

[0136] An SQL statement generating unit 105 is configured to generate, based on the field type and the full amount of data, an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user;

[0137] The synchronization unit 106 is configured to execute the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested to be synchronized by the user to the database to be synchronized.

[0138] The data synchronization device of the embodiment of the present application can achieve the purpose of synchronizing the database tables requested by the user by dynamically identifying the field types of the database tables requested to be synchronized by the user, reading the full amount of data of the database tables requested to be synchronized by the user under the target database instance, and generating SQL statements for inserting data corresponding to each database table requested to be synchronized by the user. The user does not need to write backup or initialization scripts for each database table to be synchronized. It only needs to pre-configure the benchmark database IP set and benchmark database set so that the user can select the target benchmark database corresponding to the target benchmark database IP to synchronize data during human-computer interaction. This saves the time of synchronizing database tables when upgrading or backing up the database system and improves the efficiency of data updates.

[0139] Furthermore, the data synchronization device may further include:

[0140] The first judgment unit is configured to determine whether the full data of each database table requested for synchronization by the user is complete. If so, the SQL statement generation unit may be executed. If not, the database tables requested for synchronization by the user in the corresponding target database instance are traversed and the database table processing unit is re-executed to read the unread rows of data in the database tables requested for synchronization by the user. After all data is read, the field types of the read database tables are identified. After the database table processing unit is executed, the SQL statement generation unit is executed.

[0141] Furthermore, the data synchronization device may further include:

[0142] A second judgment unit is used to judge whether the database table requested to be synchronized by the user is synchronized successfully after the synchronization unit is executed;

[0143] a first output unit, configured to output the database table after successful synchronization when the execution result of the second judgment unit is yes;

[0144] The recording unit is configured to store the database tables that failed to be synchronized in a preset synchronization failure database when the execution result of the second judgment unit is no, and record the reason for the failure of each synchronization failure database table.

[0145] Furthermore, the data synchronization device may further include:

[0146] A second output unit is configured to output the database table that failed to be synchronized and the reason for the synchronization failure after the recording unit is executed, so as to facilitate the user to perform data repair;

[0147] The confirmation unit is used to confirm whether the database table that failed to be centrally synchronized with the reference database has been repaired, and after confirming that the database table that failed to be centrally synchronized with the reference database has been repaired, return to execute the database table processing unit.

[0148] Among them, the specific processing flow of each unit included in the above-mentioned data synchronization device can refer to the relevant introduction of the method part above, and will not be repeated here.

[0149] The data synchronization device provided in the embodiment of the present application can be applied to data synchronization devices, such as terminals: mobile phones, computers, etc. Optionally, Figure 6 The hardware structure diagram of the data synchronization device is shown in FIG. Figure 6 The hardware structure of the data synchronization device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4.

[0150] In an embodiment of the present application, the number of processor 1 , communication interface 2 , memory 3 , and communication bus 4 is at least one, and the processor 1 , communication interface 2 , and memory 3 communicate with each other through the communication bus 4 .

[0151] The processor 1 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;

[0152] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory;

[0153] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to implement each processing flow in the aforementioned terminal data synchronization method.

[0154] An embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to implement various processing flows of the aforementioned terminal in the data synchronization method.

[0155] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0156] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0157] The above description of the disclosed embodiments is intended to enable those skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. The various embodiments may be combined with one another. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A data synchronization method, characterized in that: include: Get the target benchmark database IP address corresponding to the database table that the user requests to synchronize; Determining a target benchmark database corresponding to the target benchmark database IP from a pre-configured benchmark database set; Determine, from the target reference database, a target database instance corresponding to the database table synchronized with the user request; Dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full amount of data of the database table requested to be synchronized by the user under the target database instance; Generate an SQL statement for inserting data corresponding to each database table requested by the user for synchronization based on the field type and the full amount of data; Execute the SQL statement of inserting data in the database to be synchronized, so as to synchronize the database table requested by the user to the database to be synchronized; Before generating, based on the field type and the full amount of data, an SQL statement for inserting data corresponding to each database table requested for synchronization by the user, the method further includes: Determine whether the full amount of data in each database table requested for synchronization by the user is complete; If yes, then executing the step of generating an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user based on the field type and the full amount of data; If not, traverse the database tables that the user requested to synchronize in the corresponding target database instance, reread the unread row data in the database tables that the user requested to synchronize, and after all the data has been read, re-identify the field types of the read database tables, and execute the steps of generating SQL statements for inserting data corresponding to each database table that the user requested to synchronize based on the field types and the full amount of data; The process of determining whether the full amount of data of each database table requested to be synchronized by the user is complete includes: Compare the full amount of data of each database table requested to be synchronized by the user with the full amount of data of each database table requested to be synchronized by the user in the target database instance to see whether they are consistent; if they are consistent, it is determined that the full amount of data of each database table requested to be synchronized by the user is complete; if they are inconsistent, it is determined that the full amount of data of each database table requested to be synchronized by the user is incomplete; or, Compare and determine whether the calculated MD5 value of each database table requested to be synchronized by the user in the target database instance is the same as the MD5 value of each database table requested to be synchronized by the user in the read target database instance; if they are the same, it is determined that the full amount of data of each database table requested to be synchronized by the user is complete; if they are not the same, it is determined that the full amount of data of each database table requested to be synchronized by the user is incomplete.

2. The data synchronization method according to claim 1, characterized in that: After executing the SQL statement for inserting data in the database to be synchronized to synchronize the database table requested by the user to the database to be synchronized, the method further includes: Determine whether the database table requested by the user is synchronized successfully; If yes, output the database table after successful synchronization; If not, the database tables that failed to synchronize are stored in a preset synchronization failure database, and the reason for the synchronization failure of each database table that failed to synchronize is recorded.

3. The data synchronization method according to claim 2, wherein: After storing the database tables that failed to synchronize in a preset synchronization failure database and recording the reason for the synchronization failure of each database table that failed to synchronize, the method further includes: Output the database tables that failed to synchronize and the reasons for synchronization failure, so that users can repair the data; After confirming that the database table that failed to be synchronized in the benchmark database has been repaired, the process returns to the step of dynamically identifying the field type of the database table requested to be synchronized by the user from the target database instance, and reading the full data of the database table requested to be synchronized by the user under the target database instance.

4. A data synchronization device, characterized in that: include: An IP acquisition unit is used to obtain the target reference database IP corresponding to the database table that the user requests to synchronize; A database acquisition unit, configured to determine a target reference database corresponding to the target reference database IP from a pre-configured reference database set; an instance acquisition unit, configured to determine, from the target reference database, a target database instance corresponding to a database table synchronized with a user request; A database table processing unit, configured to dynamically identify the field type of the database table requested to be synchronized by the user from the target database instance, and read the full amount of data of the database table requested to be synchronized by the user under the target database instance; An SQL statement generating unit, configured to generate, based on the field type and the full amount of data, an SQL statement for inserting data corresponding to each database table requested to be synchronized by the user; A synchronization unit, configured to execute the SQL statement for inserting data in the database to be synchronized, so as to synchronize the database table requested by the user to the database to be synchronized; Also includes: A first judgment unit is used to judge whether the full amount of data of each database table requested to be synchronized by the user is complete; if so, execute the SQL statement generation unit; If not, traverse the database table that the user requested to synchronize in the corresponding target database instance, re-execute the database processing unit to read the unread row data in the database table that the user requested to synchronize, until all the data is read, and identify the full amount of data in the read database table; and after executing the database table processing unit, execute the SQL statement generation unit; The process of the first judging unit judging whether the full amount of data of each database table requested to be synchronized by the user is complete includes: Compare the full amount of data of each database table requested to be synchronized by the user with the full amount of data of each database table requested to be synchronized by the user in the target database instance to see whether they are consistent; if they are consistent, it is determined that the full amount of data of each database table requested to be synchronized by the user is complete; if they are inconsistent, it is determined that the full amount of data of each database table requested to be synchronized by the user is incomplete; or, Compare and determine whether the calculated MD5 value of each database table requested to be synchronized by the user in the target database instance is the same as the MD5 value of each database table requested to be synchronized by the user in the read target database instance; if they are the same, it is determined that the full amount of data of each database table requested to be synchronized by the user is complete; if they are not the same, it is determined that the full amount of data of each database table requested to be synchronized by the user is incomplete.

5. The data synchronization device according to claim 4, characterized in that: Also includes: A second judgment unit is used to judge whether the database table requested to be synchronized by the user is synchronized successfully after the synchronization unit is executed; a first output unit, configured to output the database table after successful synchronization when the execution result of the second judgment unit is yes; The recording unit is configured to store the database tables that failed to be synchronized in a preset synchronization failure database when the execution result of the second judgment unit is no, and record the reason for the failure of each synchronization failure database table.

6. The data synchronization device according to claim 4, characterized in that: Also includes: The second output unit is used to output the database table that failed to synchronize and the reason for the synchronization failure after the recording unit is executed, so that the user can repair the data; The confirmation unit is used to confirm whether the database table that failed to be synchronized in the reference database has been repaired, and if so, return to execute the database table processing unit.

7. A data synchronization device, characterized in that: including memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement the steps of the data synchronization method according to any one of claims 1 to 3.

8. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the data synchronization method according to any one of claims 1 to 3 is implemented.

Citation Information

Patent Citations

  • Method for achieving automatic synchronization of multi-source heterogeneous data resources

    CN103617176A

  • Rapid database-system-across data increment migration method

    CN105373621A