Data synchronization method and device, equipment and medium

By creating a new table with the same structure as the source data table in the target database and synchronizing data, the lock table problem caused by inconsistent table structure is solved, and the availability and stability of the database is improved.

CN120371913APending Publication Date: 2025-07-25BEIJING CO WHEELS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410101163.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-24
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

In the prior art, when the source database and the target database table structure are inconsistent, directly modifying the target database table structure may lead to table locking, affecting database performance and stability.

Method used

Create a new data table with the same structure as the source data table in the target database, and synchronize the data into the new table, delete the original data table, and avoid directly modifying the target data table structure.

Benefits of technology

Improve the availability and stability of database services, and avoid lock table problems caused by database version, system differences and high concurrent services.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120371913A_ABST
    Figure CN120371913A_ABST
Patent Text Reader

Abstract

The invention discloses a data synchronization method and device, equipment and a medium, and relates to the technical field of databases. The data synchronization method applied to the electronic equipment comprises the steps that a data synchronization request is received, and the data synchronization request is used for synchronizing data in a first database into a second database; in response to the data synchronization request, analyzing a target file corresponding to the first database to obtain table structure information of a first data table in the first database, the first data table being a data table with a changed table structure; under the condition that a second data table with the same name as the first data table exists in a second database, creating a third data table with the same table structure as the first data table in the second database based on the table structure information; and synchronizing the data in the first data table into the third data table, and deleting the second data table. Through the scheme disclosed by the invention, the availability and stability of database services can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the technical field of databases, and particularly relates to a data synchronization method, apparatus, device, and medium. Background Art

[0002] Database data synchronization is to synchronize the data in the source database to the target database.

[0003] In the related art, when the table structure of the source data table in the source database changes for data synchronization, usually the table structure of the target data table corresponding to the source data table (i.e., with the same name) in the target database is first modified to make the table structure of the target data table the same as that of the source data table. Then, the data in the source data table is synchronized to the target data table. However, affected by certain factors (such as different versions of the source database and the target database, different database systems of the source database and the target database, high-concurrency services, etc.), directly modifying the table structure of the target data table may cause a table locking situation, resulting in the unavailability of the target data table, affecting the performance of the target database, and causing the availability and stability of the target database service to decline. Summary of the Invention

[0004] Embodiments of this application provide a data synchronization method, apparatus, device, and medium, which can improve the availability and stability of database services.

[0005] In a first aspect, embodiments of this application provide a data synchronization method, which is applied to an electronic device. The method includes:

[0006] Receiving a data synchronization request, where the data synchronization request is used to synchronize the data in the first database to the second database;

[0007] In response to the data synchronization request, parsing the target file corresponding to the first database to obtain the table structure information of the first data table in the first database, where the first data table is the data table whose table structure has changed;

[0008] In the case where there is a second data table with the same name as the first data table in the second database, creating a third data table with the same table structure as the first data table in the second database based on the table structure information;

[0009] Synchronizing the data in the first data table to the third data table, and deleting the second data table.

[0010] In a second aspect, embodiments of this application provide a data synchronization apparatus, which is applied to an electronic device. The apparatus includes:

[0011] A receiving module, configured to receive a data synchronization request, where the data synchronization request is used to synchronize the data in the first database to the second database;

[0012] A parsing module, configured to parse a target file corresponding to a first database in response to a data synchronization request, so as to obtain table structure information of a first data table in the first database, where the first data table is a data table whose table structure has changed;

[0013] A creating module, configured to create a third data table with the same table structure as the first data table in the second database based on the table structure information when there is a second data table with the same name as the first data table in the second database;

[0014] A synchronization module, configured to synchronize the data in the first data table to the third data table and delete the second data table.

[0015] In a third aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory storing computer program instructions; when the processor reads and executes the computer program instructions, the steps of the data synchronization method provided by the embodiment of the present application are implemented.

[0016] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the steps of the data synchronization method provided by the embodiment of the present application are implemented.

[0017] In a fifth aspect, an embodiment of the present application provides a computer program product, and when the instructions in the computer program product are executed by a processor of an electronic device, the electronic device is enabled to execute the steps of the data synchronization method provided by the embodiment of the present application.

[0018] In the embodiment of the present application, after receiving a data synchronization request for synchronizing the data in the first database to the second database, a target file corresponding to the first database is parsed to obtain table structure information of a first data table whose table structure has changed in the first database; when there is a second data table with the same name as the first data table in the second database, a third data table with the same table structure as the first data table is created in the second database based on the table structure information of the first data table; the data in the first data table is synchronized to the third data table, and the second data table is deleted. In this way, when synchronizing the data in the first data table in the first database to the second database, the table structure of the second data table corresponding to the first data table in the second database is not directly modified, and the data synchronization is not affected by factors such as database version, database system, and high-concurrency services, and the lock table situation will not occur, thereby not affecting the performance of the second database, and the availability and stability of the database service can be improved. Description of the Drawings

[0019] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the accompanying drawings required for the embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.

[0020] Figure 1 is a schematic flowchart of the data synchronization method provided by the embodiments of the present application;

[0021] Figure 2 is a schematic structural diagram of the data synchronization device provided by the embodiments of the present application;

[0022] Figure 3 is a schematic structural diagram of the electronic device provided by the embodiments of the present application. Detailed implementation manners

[0023] In order to be able to more clearly understand the above objects, features, and advantages of the present application, the following will further describe the solutions of the present application. It should be noted that, without conflict, the embodiments of the present application and the features in the embodiments can be combined with each other.

[0024] Many specific details are set forth in the following description in order to fully understand the present application, but the present application can also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only a part of the embodiments of the present application, rather than all the embodiments.

[0025] The following will, with reference to the accompanying drawings, detail the data synchronization method, device, equipment, and medium provided by the embodiments of the present application through specific embodiments and their application scenarios.

[0026] The data synchronization method and device provided by the embodiments of the present application can be applied to an electronic device.

[0027] Figure 1 is a schematic flowchart of the data synchronization method provided by the embodiments of the present application. As Figure 1 shown, the data synchronization method may include:

[0028] Step 101: Receive a data synchronization request, where the data synchronization request is used to synchronize the data in the first database to the second database;

[0029] The embodiments of the present application do not limit the manner of receiving the data synchronization request, and any available manner can be applied to the embodiments of the present application. For example, receive the data synchronization request through a control for receiving the data synchronization request. When the user clicks the control, the data synchronization request is received; for another example, when the user edits the data synchronization command and then executes the data synchronization command, the data synchronization request is received.

[0030] Step 102: In response to a data synchronization request, parse the target file corresponding to the first database to obtain the table structure information of the first data table in the first database, where the first data table is the data table whose table structure has changed;

[0031] In some possible implementations of the embodiments of the present application, the target file in the embodiments of the present application may be a log file recording all changes occurring in the first database. By parsing this log file, the Data Definition Language (DDL) statements corresponding to each data table in the first database can be obtained. The DDL statements are used to define or modify the database and the structure of the tables therein. For example, creating, deleting, and changing database objects, etc. Parsing the DDL statements can obtain the types corresponding to the DDL statements (such as creating, deleting, updating, etc.), the data tables involved, the names of the changed fields, the added or deleted indexes or constraint conditions, etc.

[0032] The embodiments of the present application do not limit the manner of parsing the log file of the database, and any available manner can be applied to the embodiments of the present application. For example, parse the log file of the database through a database log parser.

[0033] In some possible implementations of the embodiments of the present application, after parsing the log file of the database, the parsing results corresponding to each data table can be integrated into a preset data structure convenient for subsequent management for subsequent processing and operations. The data structure includes, but is not limited to: the time sequence of DDL statement execution, DDL statement types and parameters, etc.

[0034] The table structure information in the embodiments of the present application refers to the fields included in the data table, field names, field types, field lengths, primary keys, foreign keys, etc.

[0035] Step 103: In the case where there is a second data table with the same name as the first data table in the second database, create a third data table with the same table structure as the first data table in the second database based on the table structure information;

[0036] In some possible implementations of the embodiments of the present application, in step 103, the table structure information of the first data table can be used as a parameter to execute the DDL statement corresponding to creating a table to create a third data table in the second database. In this DDL statement, the table name is the table name of the third data table.

[0037] In some possible implementations of the embodiments of the present application, in step 103, it is also possible to first execute the DDL statement corresponding to the table to create a third data table in the second database, and the table name in this DDL statement is the table name of the third data table. Then, sequentially execute the DDL statements similar to the DDL statement corresponding to the first data table in the order of the DDL statement corresponding to the first data table, where the table name in the DDL statement similar to the DDL statement corresponding to the first data table is the table name of the third data table.

[0038] In some possible implementations of the embodiments of the present application, in step 103, it is also possible to create a third data table in the second database by the LIKE table creation method. Among them, the LIKE table creation method can create a table with exactly the same table structure, including all fields, indexes, data types, etc.

[0039] The DDL statement for creating a third data table in the second database by the LIKE table creation method is:

[0040] Create Table ‘Third Data Table’ LIKE ‘First Data Table’

[0041] In some possible implementations of the embodiments of the present application, after creating a third data table with the same table structure as the first data table in the second database, the data synchronization method provided by the embodiments of the present application may further include: verifying whether the table structure of the third data table is the same as that of the first data table by comparing the DDL statement for creating the third data table and the DDL statement for creating the first data table, or by comparing the table structure of the third data table and the table structure of the first data table; in the case where the table structure of the third data table is the same as that of the first data table, execute step 104.

[0042] In some possible implementations of the embodiments of the present application, the DDL statement for creating the third data table and the DDL statement for creating the first data table can be viewed and displayed through the SHOW keyword, and whether the table structure of the third data table is the same as that of the first data table can be verified by comparing the creation statements of the two data tables.

[0043] In some possible implementations of the embodiments of the present application, the DESC keyword can be used to display the table structure of the third data table and the table structure of the first data table, and whether the table structure of the third data table is the same as that of the first data table can be verified by comparing the table structures of the two data tables.

[0044] Ensuring that the table structure of the third data table is the same as that of the first data table is the key to realizing data synchronization. The same table structure of the third data table and the first data table can ensure that the third data table can receive all the data of the first data table and enable the third data table to have the same behavior and performance characteristics as the first data table.

[0045] In the embodiment of the present application, it can be ensured that the table structure of the third data table is the same as that of the first data table, thereby avoiding errors in subsequent data synchronization and improving the availability and stability of the database service.

[0046] Step 104: Synchronize the data in the first data table to the third data table and delete the second data table.

[0047] In some possible implementations of the embodiment of the present application, step 104 may include: synchronizing the full amount of data in the first data table before the table structure change to the third data table; synchronizing the incremental data in the first data table after the table structure change to the third data table.

[0048] Among them, the full amount of data in the embodiment of the present application refers to all the data in the first data table before the table structure of the first data table changes. The incremental data in the embodiment of the present application refers to the data added to the first data table after the table structure of the first data table changes.

[0049] In some possible implementations of the embodiment of the present application, for the full amount of data, the full amount of data can be synchronized to the third data table by means of copying. For the incremental data, the incremental data can be synchronized to the third data table by sequentially executing statements for data changes (including but not limited to addition, deletion, and modification).

[0050] In some possible implementations of the embodiment of the present application, before synchronizing the full amount of data in the first data table before the table structure change to the third data table, the data synchronization method provided in the embodiment of the present application further includes: obtaining the position information of the DDL statement corresponding to the table structure change of the first data table in the target file, where the position information is obtained by parsing the target file; determining the data existing in the first data table before the time corresponding to the position information as the full amount of data.

[0051] In some possible implementations of the embodiment of the present application, by parsing the above target file (i.e., the log file recording all changes occurring on the first database), the position information (which can be called the locus) of the DDL statement corresponding to the table structure change of the first data table in the target file can also be obtained. This position information can provide an accurate positioning for the synchronization of incremental data. After parsing out the position information of the DDL statement corresponding to the table structure change of the first data table in the target file, the data existing in the first data table before the time corresponding to the position information can be used as the full amount of data.

[0052] In some possible implementations of the embodiments of the present application, before synchronizing all the data in the first data table before the table structure change to the third data table, the data synchronization method provided by the embodiments of the present application further includes: performing consistency verification and integrity verification on the data in the third data table; correspondingly, synchronizing all the data in the first data table before the table structure change to the third data table may include: when the data in the third data table passes the consistency verification and integrity verification, synchronizing the incremental data to the third data table.

[0053] In database technology, data consistency means that the data in the database should be consistent at any point in time. That is to say, when modifying, adding, or deleting data in the database, the data in the database should always meet the pre-defined rules and constraints; data integrity means that the data in the database meets the pre-defined rules and constraints, and these rules and constraints can ensure the correctness and consistency of the data in the database.

[0054] The embodiments of the present application do not limit the methods used for data consistency verification and data integrity verification, and any available methods can be applied to the embodiments of the present application. For example, data consistency verification can be performed through transaction mechanisms, lock mechanisms, isolation level mechanisms, etc., and data integrity verification can be performed through primary key, foreign key, trigger mechanisms, etc.

[0055] In the embodiments of the present application, data consistency verification can ensure that the data in two data tables is consistent, and integrity verification can ensure the validity and correctness of the data and prevent data anomalies.

[0056] In some possible implementations of the embodiments of the present application, before synchronizing the incremental data in the first data table after the table structure change to the third data table, the data synchronization method provided by the embodiments of the present application further includes: modifying the name of the second data table during the system redundancy time of the electronic device; modifying the name of the third data table to the name of the first data table.

[0057] Among them, the system redundancy time refers to the idle time of the processor when the utilization rate of the processor is lower than the preset upper limit of the utilization rate.

[0058] Exemplarily, the names of the first data table and the second data table are XXX, and the name of the third data table is XXX_snap. First, modify the name of the second data table from "XXX" to "XXX_old", and then modify the name of the third data table from "XXX_snap" to "XXX".

[0059] In the embodiment of the present application, by modifying the name of the data table during the system redundancy time of the electronic device, it is possible to avoid the situation of incorrect modification of the data table name when the utilization rate of the processor of the electronic device is relatively high. And by modifying the name of the data table, it is possible to ensure that there is only one data table in the second database that has the same name as the first data table and whose data is synchronized, thereby ensuring the accuracy of data synchronization.

[0060] It should be noted that for the data tables in the first database whose table structures have not changed, their data can be directly synchronized to the corresponding data tables in the second database that have the same table structures.

[0061] Exemplarily, assume that there is an employee information table in the first database. There are two fields in this table. One field is the employee ID of integer type, and the other field is the employee name of character type. There are two records in this table. One record is "employee ID is 001, employee name is Zhang San", and the other record is "employee ID is 002, employee name is Li Si". There is an employee information table in the second database that is the same as this employee information table.

[0062] In the employee information table in the first database, add a "hire date" field of datetime type through a DDL statement, and insert a record "employee ID is 003, employee name is Wang Wu, hire date is XX / XX / XX" in the employee information table, modify Zhang San's hire date to YY / YY / YY, and modify Li Si's hire date to ZZ / ZZ / ZZ.

[0063] First, create a third data table in the second database that has the same table structure as the employee information table in the first database. For example, create table 'employee information table_snap' like 'employee information table in the first database'.

[0064] Then, verify whether the table structure of the employee information table_snap is the same as that of the employee information table in the first database. For example, show create table 'employee information table_snap'; show create table 'employee information table in the first database', and compare the create statements of the two tables to ensure that the table structure of the employee information table_snap is the same as that of the employee information table in the first database.

[0065] When the table structure of the employee information table_snap is the same as that of the employee information table in the first database, before the DDL statement for adding the "hire date" field of the date and time type, the data in the employee information table in the first database is synchronized to the employee information table_snap. At this time, there are two records in the employee information table_snap. One record is "employee ID is 001, employee name is Zhang San", and the other record is "employee ID is 002, employee name is Li Si".

[0066] Perform data integrity and data consistency verification on the employee information table_snap.

[0067] After the employee information table_snap passes the data integrity and data consistency verification, change the name of the employee information table in the second database to 'employee information table_old', and change the name of the employee information table_snap to the employee information table.

[0068] In this employee information table, insert the record "employee ID is 003, employee name is Wang Wu, hire date is XX / XX / XX", change Zhang San's hire date to YY / YY / YY, and change Li Si's hire date to ZZ / ZZ / ZZ. Delete the employee information table_old. Thus, the synchronization of the employee information table in the first database to the second database is completed.

[0069] In the embodiment of the present application, after receiving a data synchronization request for synchronizing the data in the first database to the second database, parse the target file corresponding to the first database to obtain the table structure information of the first data table whose table structure has changed in the first database; in the case where there is a second data table with the same name as the first data table in the second database, based on the table structure information of the first data table, create a third data table with the same table structure as the first data table in the second database; synchronize the data in the first data table to the third data table, and delete the second data table. In this way, when synchronizing the data in the first data table in the first database to the second database, the table structure of the second data table corresponding to the first data table in the second database is not directly modified, and the data synchronization is not affected by factors such as database version, database system, and high-concurrency services, and there will be no lock table situation, and thus the performance of the second database will not be affected, and the availability and stability of the database service can be improved.

[0070] Corresponding to the above method embodiment, the embodiment of the present application also provides a data synchronization device. As Figure 2 shown, Figure 2 is a schematic structural diagram of the data synchronization device provided by the embodiment of the present application. The data synchronization device 200 may include:

[0071] A receiving module 201, configured to receive a data synchronization request, where the data synchronization request is used to synchronize data in a first database to a second database;

[0072] A parsing module 202, configured to, in response to the data synchronization request, parse a target file corresponding to the first database to obtain table structure information of a first data table in the first database, where the first data table is a data table whose table structure has changed;

[0073] A creating module 203, configured to, when there is a second data table corresponding to the first data table in the second database, create a third data table with the same table structure as the first data table in the second database based on the table structure information;

[0074] A synchronization module 204, configured to synchronize data in the first data table to the third data table and delete the second data table.

[0075] In an embodiment of the present application, after receiving a data synchronization request for synchronizing data in a first database to a second database, a target file corresponding to the first database is parsed to obtain table structure information of a first data table whose table structure has changed in the first database; when there is a second data table with the same name as the first data table in the second database, a third data table with the same table structure as the first data table is created in the second database based on the table structure information of the first data table; the data in the first data table is synchronized to the third data table, and the second data table is deleted. In this way, when synchronizing the data in the first data table in the first database to the second database, the table structure of the second data table corresponding to the first data table in the second database is not directly modified, and the data synchronization is not affected by factors such as database version, database system, and high-concurrency services, and the situation of table locking will not occur, thereby not affecting the performance of the second database, and the availability and stability of the database service can be improved.

[0076] In some possible implementations of the embodiment of the present application, the synchronization module 204 includes:

[0077] A first synchronization sub-module, configured to synchronize all the data in the first data table before the table structure change to the third data table;

[0078] A second synchronization sub-module, configured to synchronize the incremental data in the first data table after the table structure change to the third data table.

[0079] In some possible implementations of the embodiment of the present application, the data synchronization device 200 provided in the embodiment of the present application may further include:

[0080] An acquisition module, configured to acquire the location information of the DDL statement corresponding to the change in the table structure of the first data table in the target file, where the location information is obtained by parsing the target file.

[0081] A determination module, configured to determine the data that existed in the first data table before the time corresponding to the location information as full-volume data.

[0082] In some possible implementations of the embodiments of the present application, the data synchronization device 200 provided in the embodiments of the present application may further include:

[0083] A verification module, configured to perform consistency verification and integrity verification on the data in the third data table, and trigger the second synchronization sub-module when the data in the third data table passes the consistency verification and integrity verification.

[0084] In some possible implementations of the embodiments of the present application, the data synchronization device 200 provided in the embodiments of the present application may further include:

[0085] A rename module, configured to modify the name of the second data table during the system redundancy time of the electronic device, and modify the name of the third data table to the name of the first data table.

[0086] In some possible implementations of the embodiments of the present application, the data synchronization device 200 provided in the embodiments of the present application may further include:

[0087] A verification module, configured to verify whether the table structure of the third data table is the same as that of the first data table by comparing the DDL statement for creating the third data table with the DDL statement for creating the first data table, or by comparing the table structure of the third data table with the table structure of the first data table; and trigger the synchronization module 204 when the table structure of the third data table is the same as that of the first data table.

[0088] Figure 3 It is a schematic structural diagram of an electronic device provided in the embodiments of the present application.

[0089] The electronic device may include a processor 301 and a memory 302 storing computer program instructions.

[0090] Specifically, the above-mentioned processor 301 may include 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 application.

[0091] The memory 302 may include a mass memory for data or instructions. By way of example and not limitation, the memory 302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disc, a magneto-optical disc, a magnetic tape, or a universal serial bus (USB) drive, or a combination of two or more of these. Where appropriate, the memory 302 may include removable or non-removable (or fixed) media. Where appropriate, the memory 302 may be internal or external to the electronic device. In some specific embodiments, the memory 302 is a non-volatile solid-state memory.

[0092] In some specific embodiments, the memory may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk storage media device, an optical storage media device, a flash memory device, an electrical, optical, or other physical / tangible memory storage device. Thus, generally, the memory includes one or more tangible (non-transitory) computer-readable storage media (e.g., memory devices) encoded with software including computer-executable instructions, and when the software is executed (e.g., by one or more processors), it is operable to perform the operations described with reference to the data synchronization method according to the present application.

[0093] The processor 301 reads and executes the computer program instructions stored in the memory 302 to implement the data synchronization method provided by the embodiments of the present application.

[0094] In some examples, the electronic device may further include a communication interface 303 and a bus 310. Among them, as Figure 3 shown, the processor 301, the memory 302, and the communication interface 303 are connected through the bus 310 and complete communication with each other.

[0095] The communication interface 303 is mainly used to implement communication between the various modules, devices, units, and / or devices in the embodiments of the present application.

[0096] The bus 310 includes hardware, software, or both, and couples the components of the electronic device to each other. By way of example and not limitation, the bus may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable bus or a combination of two or more of these. Where appropriate, the bus 310 may include one or more buses. Although the embodiments of the present application describe and illustrate specific buses, the present application contemplates any suitable bus or interconnect.

[0097] The electronic device can execute the data synchronization method provided by the embodiments of the present application, so as to achieve the corresponding technical effects of the data synchronization method provided by the embodiments of the present application.

[0098] In addition, in combination with the data synchronization method in the above embodiments, the embodiments of the present application also provide a computer-readable storage medium to implement. Computer program instructions are stored on the computer-readable storage medium; when the computer program instructions are executed by a processor, the data synchronization method provided by the embodiments of the present application is implemented. Examples of computer-readable storage media include non-transitory computer-readable media, such as ROM, RAM, magnetic disks, or optical discs.

[0099] The embodiments of the present application also provide a computer program product. When the instructions in the computer program product are executed by the processor of the electronic device, the electronic device is caused to execute the data synchronization method provided by the embodiments of the present application, and the same technical effects can be achieved. To avoid repetition, it will not be elaborated here.

[0100] It should be noted that in this article, relational terms such as "first" and "second" are only used 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 term "comprising" or any other variant thereof is 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 expressly listed, or elements that are inherent to such process, method, article, or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the said element.

Claims

1. A data synchronization method, characterized in that, The method includes: Receiving a data synchronization request, where the data synchronization request is used to synchronize data in a first database to a second database; In response to the data synchronization request, parsing a target file corresponding to the first database to obtain table structure information of a first data table in the first database, where the first data table is a data table whose table structure has changed; In the case where there is a second data table with the same name as the first data table in the second database, based on the table structure information, creating a third data table with the same table structure as the first data table in the second database; Synchronizing the data in the first data table to the third data table and deleting the second data table.

2. The method according to claim 1, wherein The synchronizing the data in the first data table to the third data table includes: Synchronizing all the data in the first data table before the change of the table structure to the third data table; Synchronizing the incremental data in the first data table after the change of the table structure to the third data table.

3. The method according to claim 2, characterized in that, Before synchronizing all the data in the first data table before the change of the table structure to the third data table, the method includes: Obtaining position information of a data definition language statement corresponding to the change of the table structure of the first data table in the target file, where the position information is obtained by parsing the target file; Determining the data that existed in the first data table before the time corresponding to the position information as the all data.

4. The method according to claim 2, characterized in that Before synchronizing the incremental data in the first data table after the change of the table structure to the third data table, the method further includes: Performing consistency check and integrity check on the data in the third data table; The synchronizing the incremental data in the first data table after the change of the table structure to the third data table includes: In the case where the data in the third data table passes the consistency check and the integrity check, synchronizing the incremental data to the third data table.

5. The method according to claim 2, characterized in that, Before synchronizing the incremental data in the first data table after the change of the table structure to the third data table, the method further includes: Modifying the name of the second data table during the system redundancy time of the electronic device; Modifying the name of the third data table to the name of the first data table.

6. The method according to claim 1, wherein After creating the third data table with the same table structure as the first data table in the second database, the method further includes: Verifying whether the table structure of the third data table is the same as that of the first data table by comparing the data definition language statements for creating the third data table and the data definition language statements for creating the first data table, or by comparing the table structure of the third data table and the table structure of the first data table; The synchronizing the data in the first data table to the third data table includes: In the case where the table structure of the third data table is the same as that of the first data table, synchronizing the data in the first data table to the third data table.

7. A data synchronization device, characterized in that, The device includes: A receiving module, configured to receive a data synchronization request, where the data synchronization request is used to synchronize data in a first database to a second database; A parsing module, configured to, in response to the data synchronization request, parse a target file corresponding to the first database to obtain table structure information of a first data table in the first database, where the first data table is a data table whose table structure has changed; A creating module, configured to, when there is a second data table with the same name as the first data table in the second database, create a third data table with the same table structure as the first data table in the second database based on the table structure information; A synchronizing module, configured to synchronize data in the first data table to the third data table and delete the second data table.

8. The device according to claim 7, characterized in that, The apparatus further includes: A verification module, configured to verify whether the table structure of the third data table is the same as the table structure of the first data table by comparing the data definition language for creating the third data table with the data definition language for creating the first data table, or by comparing the table structure of the third data table with the table structure of the first data table, and trigger the synchronizing module when the table structure of the third data table is the same as the table structure of the first data table.

9. An electronic device, characterized in that, The electronic device includes: a processor and a memory storing computer program instructions; The processor reads and executes the computer program instructions to implement the data synchronization method according to any one of claims 1-6.

10. A computer-readable storage medium, characterized in that, Computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by the processor, the data synchronization method according to any one of claims 1-6 is implemented.