Database synchronization methods, devices, electronic equipment and storage media
By initiating a request in the synchronized database platform to obtain the data and table structure of the source database platform, and then comparing, analyzing, and modifying them, the problem of cross-platform and cross-database synchronization is solved, achieving efficient database synchronization.
Patent Information
- Application Number
- CN202211678400.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-26
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-12-26
AI Technical Summary
Existing database synchronization methods cannot achieve cross-platform and cross-database synchronization.
By initiating a request through the synchronized database platform, synchronized data and table structures are obtained from the source database platform. Based on the table structures and data, comparative analysis and modifications are performed to generate database language to achieve cross-platform and cross-database synchronization.
It enables cross-platform and cross-database database synchronization, avoiding data loss or synchronization failure, and improving synchronization efficiency and accuracy.
Smart Images

Figure CN115827784B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computers, and more particularly to a database synchronization method, apparatus, electronic device, and storage medium. Background Technology
[0002] Existing database synchronization methods primarily rely on functions provided by cloud-based database service platforms to synchronize database content. If the cloud platform grants permission to download the data files, synchronization is then performed on the platform requiring synchronization via database commands. Therefore, existing database synchronization methods cannot achieve cross-platform or cross-database synchronization. Summary of the Invention
[0003] This invention provides a database synchronization method, apparatus, electronic device, and storage medium, aiming to achieve database synchronization across platforms and databases.
[0004] In a first aspect, the present invention provides a database synchronization method, which is applied across database platforms, the cross-database platform including a synchronization database platform and a source database platform, comprising:
[0005] Based on the acquisition request initiated by the synchronization database platform, synchronized data and the structure of the first table are obtained from the source database platform;
[0006] Obtain the local table data and the second table structure from the synchronous database platform;
[0007] Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0008] In one embodiment, the database synchronization includes table structure synchronization; based on the first table structure and the second table structure, database synchronization includes:
[0009] Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications.
[0010] The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
[0011] The database synchronization includes table data synchronization; based on the synchronized data and the local table data, database synchronization is performed, including:
[0012] Based on the primary key value of the synchronized data, determine the column to be deleted in the local table data;
[0013] Delete the data in the column to be deleted from the local table data to obtain the local table data after deletion;
[0014] Based on the synchronized data, data is inserted into the deleted local table data to complete the synchronization of the synchronized data to the local table data.
[0015] The request includes the requested library name, table name, start time, and end time.
[0016] The step of obtaining synchronized data and the structure of the first table from the source database platform according to the acquisition request initiated by the synchronization database platform includes:
[0017] Based on the requested database name, the target database in the source database platform is determined;
[0018] Retrieve the current table in the target database based on the table name;
[0019] Obtain the data modified in the current table during the start and end times, as well as the table structure of the current table;
[0020] The modified data is identified as the synchronized data, and the current table structure is identified as the first table structure.
[0021] In the source database platform, all tables in the source database have a time field, which represents the modification time of the table data. When the table data is changed, the modification time of the time field is the current change time.
[0022] Secondly, the present invention provides a database synchronization device, which is applied across database platforms, the cross-database platform including a synchronization database platform and a source database platform, comprising:
[0023] The first acquisition module is used to acquire synchronized data and the structure of the first table from the source database platform according to the acquisition request initiated by the synchronization database platform.
[0024] The second acquisition module is used to acquire local table data and the second table structure in the synchronous database platform;
[0025] The database synchronization module is used to perform database synchronization based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0026] In one embodiment, the database synchronization module is further configured to:
[0027] Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications.
[0028] The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
[0029] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the database synchronization method described in the first aspect.
[0030] Fourthly, the present invention also provides a non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium comprising a computer program, which, when executed by the processor, implements the database synchronization method described in the first aspect.
[0031] Fifthly, the present invention also provides a computer program product, the computer program product comprising a computer program, which, when executed by the processor, implements the database synchronization method described in the first aspect.
[0032] The database synchronization method, apparatus, electronic device, and storage medium provided by this invention obtain synchronized data and a first table structure from the source database platform based on an acquisition request initiated by the synchronization database platform; obtain local table data and a second table structure from the synchronization database platform; and perform database synchronization based on the synchronized data, the first table structure, the local table data, and the second table structure. During the database synchronization process, synchronization across platforms and databases is achieved through the synchronized data and the first table structure from the source database platform, as well as the local table data and the second table structure from the synchronization database platform. Attached Figure Description
[0033] To more clearly illustrate the technical solutions of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0034] Figure 1 This is a flowchart illustrating the database synchronization method provided by the present invention;
[0035] Figure 2 This is a schematic diagram of the database synchronization device provided by the present invention;
[0036] Figure 3This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0037] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0038] This invention provides an embodiment of a database synchronization method. It should be noted that although the logical order is shown in the flowchart, under certain data conditions, the steps shown or described may be performed in a different order than that shown here.
[0039] Reference Figure 1 , Figure 1 This is a flowchart illustrating the database synchronization method provided by the present invention. The database synchronization method provided in this embodiment of the present invention includes:
[0040] Step 101: Based on the acquisition request initiated by the synchronization database platform, obtain the synchronization data and the structure of the first table from the source database platform;
[0041] Step 102: Obtain local table data and the second table structure from the synchronized database platform;
[0042] Step 103: Perform database synchronization based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0043] It should be noted that the embodiments of the present invention use a database synchronization system as the execution subject as an example. The database synchronization method provided in the embodiments of the present invention is a synchronization scheme based on the table structure and data of the application, and can be applied to database synchronization between multiple platforms. For example, synchronizing an Amazon Cloud database to an Alibaba Cloud database.
[0044] It should be further noted that the database synchronization system in this embodiment of the invention is used for synchronization from the source database platform to the synchronization database platform. The source database platform can be deployed on a cloud server that can connect to the source database, and the synchronization database platform can be deployed on a server that can connect to the synchronization database.
[0045] Specifically, the synchronization database platform initiates a retrieval request to the source database platform. This retrieval request is generated by the synchronization database platform based on a task monitoring table, which records information such as the table structure and processing time of the last synchronized data. In one embodiment, the source database platform provides an API (Application Programming Interface), therefore, it can be understood that the synchronization database platform initiates the retrieval request to the source database platform through the API interface.
[0046] Therefore, the synchronization database platform sends a request to the source database platform via HTTPS (Hypertext Transfer Protocol over Secure Socket Layer) through its API interface. Upon receiving the request, the source database platform retrieves the required synchronization data and the first table structure based on the request. In essence, the synchronization database platform retrieves the synchronization data and the first table structure from the source database platform via HTTPS through its API interface.
[0047] Furthermore, after obtaining the synchronized data and the first table structure from the source database platform, the synchronization database platform queries the local table data and the current table structure (second table structure) in the synchronization database platform.
[0048] Furthermore, the synchronous database platform compares and analyzes the structure of the second table with the structure of the first table, and modifies the structure of the second table based on the analysis results.
[0049] Furthermore, after modifying the structure of the second table, the synchronization database platform compares and analyzes the synchronized data with the local table data, and modifies the local table data based on the analysis results to complete the synchronization of the synchronized data to the local table data.
[0050] The database synchronization method provided by this invention obtains synchronization data and a first table structure from the source database platform based on the acquisition request initiated by the synchronization database platform; obtains local table data and a second table structure from the synchronization database platform; and performs database synchronization based on the synchronization data, the first table structure, the local table data, and the second table structure.
[0051] During the database synchronization process, the database is synchronized across platforms and databases by using the synchronized data and the first table structure in the source database platform, as well as the local table data and the second table structure in the synchronized database platform.
[0052] Further, step 101, which describes obtaining synchronized data and the first table structure from the source database platform based on the acquisition request initiated by the synchronized database platform, includes:
[0053] Based on the requested database name, the target database in the source database platform is determined;
[0054] Retrieve the current table in the target database based on the table name;
[0055] Obtain the data modified in the current table during the start and end times, as well as the table structure of the current table;
[0056] The modified data is identified as the synchronized data, and the current table structure is identified as the first table structure.
[0057] It should be noted that, in this embodiment of the invention, all tables in the source database platform have a time field. This time field represents the modification time of the table data; when the table data changes, the modification time in the time field is replaced with the current modification time.
[0058] It should be further noted that the retrieval request initiated by the database synchronization platform must include at least the requested database name, table name, start time, and end time. The start time is the end time of the last data synchronization in the task monitoring table, and the end time is the current system time.
[0059] Specifically, after receiving the retrieval request initiated by the synchronization database platform, the source database platform compares the name of the requested database with the name of each database in the source database platform, and identifies the database in the source database platform whose name matches the name of the requested database as the target database.
[0060] Furthermore, the source database platform compares the table name with the names of all tables in the target database and obtains the current table in the target database whose name matches the table name.
[0061] Furthermore, after the source database platform obtains the current table, it retrieves the data modified in the current table during the start and end times, and identifies the modified data as synchronized data.
[0062] Furthermore, the source database platform obtains the table structure of the current table during the start and end times, and determines the table structure of the current table as the first table structure.
[0063] Furthermore, the source database platform returns the synchronized data and the structure of the first table to the synchronization database platform.
[0064] In this embodiment of the invention, the source database platform determines the data modified in the current table during the start and end times and the table structure of the current table based on the request information. This allows subsequent synchronization to focus only on the data modified during the start and end times, reducing redundant data synchronization and decreasing the amount of data synchronized per session.
[0065] It should be further noted that the database synchronization in step 103 includes table structure synchronization and table data synchronization.
[0066] Therefore, the specific steps for synchronizing table structures are as follows:
[0067] Based on the first table structure and the second table structure, database synchronization is performed, including:
[0068] Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications.
[0069] The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
[0070] It should be noted that the database synchronization in this embodiment of the invention includes table structure synchronization and table data synchronization. The database table structure modification and data modification operations used in table structure synchronization and table data synchronization are simple basic database operations that can be applied to database synchronization between various databases.
[0071] Specifically, the synchronization database platform uses the structure of the first table as a benchmark, compares and analyzes the retrieved structure of the second table with the structure of the first table, and obtains the differences between the two structures. Furthermore, based on these differences, the synchronization database platform determines the local table structure modifications, index modifications, and primary key modifications for the second table.
[0072] Furthermore, the synchronous database platform generates a database language for modifying the structure of the second table based on local table structure modifications, index modifications, and primary key modifications. This database language includes SQL (Structured Query Language).
[0073] Furthermore, by executing the aforementioned database language on the synchronization database platform and modifying the structure of the second table, the synchronization of the first table structure to the second table structure can be completed.
[0074] In this embodiment of the invention, a first table structure is used as a benchmark. The first table structure and the second table structure are compared and analyzed. Based on the analysis results, the synchronization from the first table structure to the second table structure is completed, avoiding data loss or synchronization failure caused by inconsistent table structures when only data is synchronized.
[0075] Therefore, the specific steps for synchronizing table data are as follows:
[0076] Database synchronization is performed based on the synchronized data and the local table data, including:
[0077] Based on the primary key value of the synchronized data, determine the column to be deleted in the local table data;
[0078] Delete the data in the column to be deleted from the local table data to obtain the local table data after deletion;
[0079] Based on the synchronized data, data is inserted into the deleted local table data to complete the synchronization of the synchronized data to the local table data.
[0080] Specifically, the synchronization database platform reads the primary key name from the first table structure and obtains the primary key value of the synchronized data based on the primary key name.
[0081] Furthermore, the synchronous database platform identifies the column specified by the primary key value as the column to be deleted in the local table data.
[0082] Furthermore, the synchronous database platform deletes the data corresponding to the columns to be deleted from the local table data, thus obtaining the deleted local table data.
[0083] Furthermore, the synchronous database platform uses the synchronized data as a benchmark to compare and analyze the synchronized data and the deleted local table data, and determines the missing data in the deleted local table data based on the analysis results.
[0084] Furthermore, the synchronization database platform can insert the missing data into the deleted local table data to complete the synchronization of the synchronized data to the local table data.
[0085] In this embodiment of the invention, the synchronization database platform determines the column to be deleted in the local table data based on the primary key value of the synchronization data, deletes the data in the column to be deleted, and then inserts the deleted data into the local table data, thereby achieving fast table data synchronization.
[0086] Furthermore, the database synchronization device and the database synchronization method provided by the present invention correspond to each other.
[0087] Figure 2 As shown, Figure 2This is a schematic diagram of the database synchronization device provided by the present invention. The database synchronization device includes:
[0088] The first acquisition module 201 is used to acquire synchronized data and the structure of the first table from the source database platform according to the acquisition request initiated by the synchronized database platform.
[0089] The second acquisition module 202 is used to acquire local table data and the second table structure in the synchronous database platform;
[0090] The database synchronization module 203 is used to perform database synchronization based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0091] Furthermore, the first acquisition module 201 is also used for:
[0092] Based on the requested database name, the target database in the source database platform is determined;
[0093] Retrieve the current table in the target database based on the table name;
[0094] Obtain the data modified in the current table during the start and end times, as well as the table structure of the current table;
[0095] The modified data is identified as the synchronized data, and the current table structure is identified as the first table structure.
[0096] Furthermore, the database synchronization module 203 is also used for:
[0097] Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications.
[0098] The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
[0099] Furthermore, the database synchronization module 203 is also used for:
[0100] Based on the primary key value of the synchronized data, determine the column to be deleted in the local table data;
[0101] Delete the data in the column to be deleted from the local table data to obtain the local table data after deletion;
[0102] Based on the synchronized data, data is inserted into the deleted local table data to complete the synchronization of the synchronized data to the local table data.
[0103] The specific embodiments of the database synchronization device provided by the present invention are basically the same as the embodiments of the database synchronization method described above, and will not be repeated here.
[0104] Figure 3 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330, and a communication bus 340, wherein the processor 310, the communication interface 320, and the memory 330 communicate with each other through the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute a database synchronization method. This method is applied across database platforms, including a synchronization database platform and a source database platform, comprising:
[0105] Based on the acquisition request initiated by the synchronization database platform, synchronized data and the structure of the first table are obtained from the source database platform;
[0106] Obtain the local table data and the second table structure from the synchronous database platform;
[0107] Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0108] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0109] On the other hand, the present invention also provides a computer program product, comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program including program instructions, which, when executed by a computer, enable the computer to execute the database synchronization method provided by the above methods. This method is applied across database platforms, the cross-database platform including a synchronization database platform and a source database platform, comprising:
[0110] Based on the acquisition request initiated by the synchronization database platform, synchronized data and the structure of the first table are obtained from the source database platform;
[0111] Obtain the local table data and the second table structure from the synchronous database platform;
[0112] Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0113] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the database synchronization methods provided above. This method is applied across database platforms, the cross-database platforms including a synchronization database platform and a source database platform, and includes:
[0114] Based on the acquisition request initiated by the synchronization database platform, synchronized data and the structure of the first table are obtained from the source database platform;
[0115] Obtain the local table data and the second table structure from the synchronous database platform;
[0116] Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure.
[0117] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0118] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0119] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A database synchronization method, characterized in that, The database synchronization method is applied across database platforms, which include a synchronization database platform and a source database platform, including: Based on the acquisition request initiated by the synchronization database platform, the synchronization data and the first table structure are obtained from the source database platform. The acquisition request is generated by the synchronization database platform based on the task monitoring table, which records the table structure and processing time of the last synchronization data. Obtain the local table data and the second table structure from the synchronous database platform; Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure. The database synchronization includes table structure synchronization; Based on the first table structure and the second table structure, database synchronization is performed, including: Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications. The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
2. The database synchronization method according to claim 1, characterized in that, The database synchronization includes table data synchronization; Database synchronization is performed based on the synchronized data and the local table data, including: Based on the primary key value of the synchronized data, determine the column to be deleted in the local table data; Delete the data in the column to be deleted from the local table data to obtain the local table data after deletion; Based on the synchronized data, data is inserted into the deleted local table data to complete the synchronization of the synchronized data to the local table data.
3. The database synchronization method according to claim 1, characterized in that, The request includes the requested library name, table name, start time, and end time.
4. The database synchronization method according to claim 3, characterized in that, The step of obtaining synchronized data and the structure of the first table from the source database platform according to the acquisition request initiated by the synchronization database platform includes: Based on the requested database name, the target database in the source database platform is determined; Retrieve the current table in the target database based on the table name; Obtain the data modified in the current table during the start and end times, as well as the table structure of the current table; The modified data is identified as the synchronized data, and the current table structure is identified as the first table structure.
5. The database synchronization method according to any one of claims 1 to 4, characterized in that, In the source database platform, all tables in the source database have a time field, which represents the modification time of the table data. When the table data is changed, the modification time of the time field is the current change time.
6. A database synchronization device, characterized in that, The database synchronization device is applied across database platforms, which include a synchronization database platform and a source database platform, including: The first acquisition module is used to acquire synchronized data and the first table structure from the source database platform according to the acquisition request initiated by the synchronization database platform. The acquisition request is generated by the synchronization database platform based on the task monitoring table, which records the table structure and processing time of the last synchronized data. The second acquisition module is used to acquire local table data and the second table structure in the synchronous database platform; The database synchronization module is used to perform database synchronization based on the synchronized data and the first table structure, as well as the local table data and the second table structure. Obtain the local table data and the second table structure from the synchronous database platform; Database synchronization is performed based on the synchronized data and the first table structure, as well as the local table data and the second table structure. The database synchronization includes table structure synchronization; The database synchronization module performs database synchronization based on the first table structure and the second table structure, including: Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications. The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
7. The database synchronization device according to claim 6, characterized in that, The database synchronization module is also used for: Based on the first table structure, a comparative analysis of the first table structure and the second table structure is performed to obtain local table structure modifications, index modifications, and primary key modifications. The modifications to the local table structure, the indexes, and the primary key are organized into a database language and executed to synchronize the first table structure to the second table structure.
8. An electronic device, the electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the database synchronization method according to any one of claims 1 to 5.
9. A non-transitory computer-readable storage medium, the non-transitory computer-readable storage medium comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the database synchronization method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Database synchronization method, device and equipment and storage medium
CN109885581A
Cross-platform data synchronization method and device and electronic equipment
CN111352993A