Data synchronization method, system and device and storage medium

By pushing update information to the message queue when the primary database is updated and synchronized by the message consumer to the slave database, the existing database synchronization method has been solved, and efficient and secure multi-database data consistency synchronization is achieved.

CN119669358APending Publication Date: 2025-03-21GREE ELECTRIC APPLIANCE INC OF ZHUHAI +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411763332.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-21

AI Technical Summary

Technical Problem

The existing database synchronization methods have problems such as poor timeliness, waste of resources and low synchronization efficiency, which leads to the slave database being unable to be perceived and synchronized in time when the master database is updated, resulting in data inconsistency and delay.

Method used

When data updates occur in the primary database, update information is inserted into the data table and pushed to the message queue server for message consumers to listen and synchronize to the slave database. This method utilizes the asynchronous communication mechanism of message queues to improve the timeliness and efficiency of data synchronization.

Benefits of technology

Real-time data synchronization from the database is achieved, which enhances the security of data information, ensures data consistency between multiple databases, improves the timeliness and efficiency of data synchronization, and reduces the working pressure of servers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119669358A_ABST
    Figure CN119669358A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the field of databases, and discloses a data synchronization method, system and device and a storage medium, the data synchronization method is applied to a main database, and comprises the following steps: when data update occurs in the main database, inserting update information corresponding to update data into a data table located in the main database; and reading the newly inserted update information from the data table, and pushing the read update information to a message queue server, so that a message consumer monitors and obtains the latest update information from the message queue server, and synchronizes the latest update information to the slave database, so that the slave database completes update data synchronization. According to the data synchronization method disclosed by the invention, the problems of data updating delay and low synchronization efficiency are solved, and at least the security and the synchronization efficiency of data synchronization can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of databases, and in particular to a data synchronization method, system, device and storage medium. Background Art

[0002] In the current database application field, with the continuous growth of data volume and the widespread application of distributed systems, the real-time nature of data and the consistency of data between multiple databases have become important considerations for system design and operation. Traditional database synchronization methods, such as polling-based synchronization mechanisms, often have problems such as poor timeliness, waste of resources, and low synchronization efficiency. When the master database is updated, the slave database often cannot perceive and synchronize these updates in time, resulting in data inconsistency and delay. Summary of the invention

[0003] The purpose of the present invention is to at least provide a data synchronization method, system, device and storage medium, which can at least solve the problems of data update delay and low synchronization efficiency, and at least improve the security and synchronization efficiency of data synchronization.

[0004] To solve the above technical problems, at least one embodiment of the present application provides a data synchronization method, which is applied to a master database and includes:

[0005] When data in the master database is updated, update information corresponding to the updated data is inserted into a data table located in the master database;

[0006] The newly inserted update information is read from the data table, and the read update information is pushed to the message queue server, so that the message consumer can monitor and obtain the latest update information from the message queue server, and synchronize the latest update information to the slave database, so that the slave database completes the update data synchronization.

[0007] At least one embodiment of the present application further provides a data synchronization method, which is applied to a message queue server, comprising:

[0008] Receive update information pushed by the master database and store the update information in the local message queue;

[0009] A topic is set for the newly stored update information, and based on the topic of the message subscribed by the message consumer contracted with the message queue server, the newly stored update information is pushed to the matching message consumer, so that the latest update information is synchronized to the slave database through the message consumer.

[0010] At least one embodiment of the present application further provides a data synchronization method, which is applied to a message consumer, comprising:

[0011] Based on the subject of the message subscribed to by the message queue server, the latest update information is monitored and obtained from the message queue server, where the latest update information is the update information that the master database has pushed to the message queue server, and the latest update information is the update information generated when the master database is updated;

[0012] The latest update information is synchronized to the slave database, so that the slave database completes the synchronization of update data with the master database.

[0013] At least one embodiment of the present application further provides a data synchronization method, applied to a slave database, comprising:

[0014] The receiving message consumer listens to and obtains the latest update information from the message queue server, wherein the latest update information is the update information that the master database has pushed to the message queue server, and the latest update information is the update information generated when the master database is updated;

[0015] A database statement is generated for the received update information, and the database statement is executed in the slave database to complete synchronization of the update data with the master database.

[0016] At least one embodiment of the present application further provides a data synchronization system, comprising: a master database, at least one slave database, a message queue server, and at least one message consumer;

[0017] The master database is used to insert update information corresponding to the updated data into a data table located in the master database when data is updated in the master database, and push the update information inserted in the data table to a message queue server;

[0018] The message queue server is used to receive the update information pushed by the main database, store the update information in a local message queue, and set a topic for the newly stored update information;

[0019] The message consumer is used to monitor and obtain the latest update information from the message queue server based on the subject of the message subscribed to the message queue server, and synchronize the latest update information to the slave database;

[0020] The slave database is used to receive update information pushed by the message consumer, generate database statements for the received update information, and execute the database statements to complete synchronization of update data with the master database.

[0021] At least one embodiment of the present application also provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the above-mentioned data synchronization method.

[0022] At least one embodiment of the present application further provides a computer-readable storage medium storing a computer program, wherein the computer program implements the above-mentioned data synchronization method when executed by a processor.

[0023] The data synchronization method, system, device and storage medium provided by the embodiments of the present application, by pushing the update information inserted in the data table to the message queue, the message consumer corresponding to the slave database listens to the update message from the message queue server, thereby synchronizing the update message to the slave database, completing the update data synchronization of the slave database in real time, enhancing the security of data information, and ensuring the consistency of data among multiple databases, and utilizing the efficient asynchronous communication mechanism of the message queue to improve the timeliness of data synchronization and improve the synchronization efficiency; at the same time, after the update data is recorded in the data table, the data table can be used to add relevant fields to the update data, so that different update messages can be pushed to the message queue in turn, so that the slave database can synchronize and update multiple update information in turn, avoiding the risk of synchronization errors and excessive data, reducing the workload of the server, and improving the stability and accuracy of the synchronization process.

[0024] In some optional embodiments, after inserting the update information into the data table located in the main database, the method further includes:

[0025] Setting an initial expiration time and a push mark for the update information newly inserted into the data table, wherein the starting time point of the initial expiration time is the time point corresponding to when the update information is inserted into the data table, and the push mark is set to not pushed by default;

[0026] After successfully pushing the read update information to the message queue server, it also includes:

[0027] The starting time point of the initial expiration time corresponding to the successfully pushed update information is updated to the time point corresponding to when the update information is successfully pushed, and the push mark corresponding to the successfully pushed update information is updated to pushed.

[0028] By setting an initial expiration time and a push mark for the inserted update information in the data table, the initial expiration time can be used to regularly delete the content in the data table to avoid the update information being retained in the data table after the update is completed, causing excessive storage pressure; at the same time, the push mark can be used to mark whether the push of each update information in the data table is successful, so that the update information that has not been pushed can be accurately pushed to the message queue, which is conducive to accurately pushing messages and improving the accuracy and stability of the synchronous update of update information; in addition, for the update information that is successfully pushed, the initial expiration time of the update information will be synchronously updated in the data table, so that the update information that is successfully pushed can be deleted regularly to reduce data storage pressure.

[0029] In some optional embodiments, when data update occurs in the primary database, inserting update information into a data table located in the primary database includes:

[0030] When data in the main database is updated, a prefabricated trigger is triggered to automatically insert the update information into a data table in the main database.

[0031] By automatically inserting update information into the data table of the main database through pre-made triggers, it can automatically respond to data updates in the main database, store it in the data table in real time, and then push it to the message queue for synchronization processing in real time, thereby improving the timeliness of data update synchronization and the effect of automatic synchronization.

[0032] In some optional embodiments, pushing the read update information to the message queue server includes:

[0033] The read update information is encrypted and pushed to the message queue server.

[0034] By encrypting update messages, the security of message push can be improved, data leakage can be avoided, and the security of data synchronization updates can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] One or more embodiments are exemplarily described by the pictures in the corresponding drawings, and these exemplary descriptions do not constitute limitations on the embodiments.

[0036] Figure 1 This is a process of a data synchronization method provided by an embodiment of the present application Figure 1 ;

[0037] Figure 2 This is a process of a data synchronization method provided by an embodiment of the present application Figure 2 ;

[0038] Figure 3This is the process of the data synchronization method provided by another embodiment of the present application Figure 1 ;

[0039] Figure 4 This is the process of the data synchronization method provided by another embodiment of the present application Figure 1 ;

[0040] Figure 5 This is the process of the data synchronization method provided by another embodiment of the present application Figure 1 ;

[0041] Figure 6 is a schematic diagram of a data synchronization system provided by another embodiment of the present application;

[0042] Figure 7 is a structural schematic diagram of an electronic device provided by another embodiment of the present application;

[0043] Figure 8 It is a schematic diagram of the structure of a computer-readable storage medium provided by another embodiment of the present application. DETAILED DESCRIPTION

[0044] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the embodiments of the present application will be described in detail below in conjunction with the accompanying drawings. However, it will be appreciated by those skilled in the art that in the present application, many technical details are proposed in order to enable the reader to better understand the present application. However, even without these technical details and various changes and modifications based on the following embodiments, the technical scheme claimed in the present application can also be implemented. The division of the following embodiments is for the convenience of description, and the specific implementation of the present application should not be construed as any limitation, and the various embodiments can be combined and referenced with each other under the premise of no contradiction.

[0045] In order to facilitate understanding of the embodiments of the present application, relevant content about database synchronization is first introduced here.

[0046] In the current database application field, with the continuous growth of data volume and the widespread application of distributed systems, the real-time nature of data and the consistency of data between multiple databases have become important considerations for system design and operation. During the current database synchronization, multiple slave databases usually synchronize information about the update of the master database based on a polling mechanism, that is, each slave database asks the master database in turn, and then synchronizes in turn. As a result, the existing database synchronization process often has problems such as poor timeliness, waste of resources, and low synchronization efficiency. When the master database is updated, multiple slave databases are often unable to perceive and synchronize these updates in time, resulting in data inconsistency and delays.

[0047] In order to solve the above-mentioned technical problems of data update delay and low synchronization efficiency, the present invention proposes a data synchronization method. The implementation details of the data synchronization method of this embodiment are specifically described below. The following content is only the implementation details provided for easy understanding and is not necessary for implementing this solution.

[0048] Embodiment 1:

[0049] The data synchronization method of this embodiment can be applied to electronic devices with communication, computing and data storage capabilities. The specific process can be as follows: Figure 1 As shown, the data synchronization method in this embodiment is applied to the master database, and the method specifically includes:

[0050] Step 101, when data in the master database is updated, update information corresponding to the updated data is inserted into a data table located in the master database;

[0051] Specifically, a data table is created in the main database to store the updated data of the main database, so that each updated data content in the main database can be inserted into the data table as update information, so that the data table can be used to add relevant fields to the update information, which facilitates the subsequent push synchronization of each update message in sequence, avoids the risk of synchronization errors and excessive data, reduces the workload of the server, and improves the stability and accuracy of the synchronization process.

[0052] In some examples, the fields added to the data table for update information include an ID corresponding to the update information, a string type, a timestamp type, a text type, and a push tag, wherein the text type represents the specific content of the data update, such as an SQL statement, the timestamp type represents the data expiration time, and the push tag indicates whether the data has been pushed. Accurately pushing data and recording related information through various fields is conducive to rapid response of the system and improved data synchronization efficiency, security, and accuracy.

[0053] Step 102, read the newly inserted update information from the data table, and push the read update information to the message queue server, so that the message consumer can monitor and obtain the latest update information from the message queue server, and synchronize the latest update information to the slave database, so that the slave database completes the update data synchronization.

[0054] Specifically, the master database establishes contact with multiple message consumers through the message queue server, so that the slave database corresponding to each message consumer can monitor the update information in the message queue through the message consumer, and then complete the update data synchronization. The efficient asynchronous communication mechanism of the message queue is used to improve the timeliness of data synchronization and improve synchronization efficiency.

[0055] In some examples, when a master database corresponds to multiple slave databases, the multiple databases are corresponded to multiple message consumers, so that multiple message consumers monitor through push subscription to achieve fast synchronization of multiple slave databases. Among them, the message consumer uses the synchronized end server as the execution subject of the slave database, and the message queue server uses the synchronization end server as the execution subject of the master database, thereby facilitating the message synchronization update of the master data to multiple slave databases.

[0056] In this embodiment, the update information inserted in the data table is pushed to the message queue, so that the message consumer corresponding to the slave database listens to the update message from the message queue server, thereby synchronizing the update message to the slave database, completing the update data synchronization of the slave database in real time, enhancing the security of data information, and ensuring the consistency of data among multiple databases. The efficient asynchronous communication mechanism of the message queue is utilized to improve the timeliness of data synchronization and the synchronization efficiency. At the same time, after the update data is recorded in the data table, the data table can be used to add relevant fields to the update data, so that different update messages can be pushed to the message queue in turn, so that the slave database can synchronize and update multiple update information in turn, avoiding the risk of synchronization errors and excessive data, reducing the workload of the server, and improving the stability and accuracy of the synchronization process.

[0057] In some embodiments, step 101 may be performed by Figure 2 The steps shown are implemented, specifically including:

[0058] Step 201, setting an initial expiration time and a push mark for the update information newly inserted into the data table, the starting time point of the initial expiration time is the time point corresponding to the insertion of the update information into the data table, and the push mark is set to not pushed by default;

[0059] Specifically, by setting an initial expiration time and a push mark for the inserted update information in the data table, the initial expiration time can be used to regularly delete the content in the data table to avoid the update information being retained in the data table after the update is completed, causing excessive storage pressure; at the same time, the push mark can be used to mark whether each update information in the data table is pushed successfully, so that the update information that has not been pushed can be accurately pushed to the message queue, which is conducive to accurately pushing messages and improving the accuracy and stability of synchronous updating of update information.

[0060] After successfully pushing the read update information to the message queue server in step 102, the following steps are also included:

[0061] Step 202: Update the starting time point of the initial expiration time corresponding to the successfully pushed update information to the time point corresponding to the successful push of the update information, and update the push mark corresponding to the successfully pushed update information to pushed.

[0062] Specifically, for the update information that is pushed successfully, the initial expiration time of the update information will be synchronously updated in the data table, so that the update information that is pushed successfully can be deleted regularly, reducing the pressure on data storage.

[0063] In some examples, by setting an expiration time, the slave database does not directly delete the data when synchronously updating the data. Therefore, if the slave database update fails, the delayed deletion of the data can be used as a safeguard, that is, the slave database can re-execute the update process and re-update the initial expiration time of the update information when the update information is re-obtained from the database until the slave database update is successful.

[0064] In some embodiments, step 101 specifically includes: when data update occurs in the primary database, triggering a prefabricated trigger to automatically insert update information into a data table located in the primary database.

[0065] Among them, when the data in the main database is updated, the process of updating the main data can also be set, so that the update information can be automatically inserted into the data table through a trigger or a stored procedure. In this embodiment, the trigger is used as an example to illustrate that the data update of the main database automatically triggers the data storage process, which is convenient for real-time storage in the data table, and then pushed to the message queue in real time for synchronization processing, thereby improving the timeliness of data update synchronization and the automatic synchronization effect.

[0066] In some embodiments, in order to improve the security of data transmission, pushing the read update information to the message queue server in step 102 includes: encrypting the read update information and then pushing it to the message queue server.

[0067] By encrypting update messages, the security of message push can be improved, data leakage can be avoided, and the security of data synchronization updates can be improved.

[0068] In some examples, the data encryption process can use AES symmetric encryption, with the sending end saving the private key and the receiving end saving the public key. After the private key is encrypted, the encrypted data is transmitted and then decrypted by the receiving end using the public key. In this embodiment, the sending end is the master database and the receiving end is the message consumer of the slave database to improve the security of data synchronization and update.

[0069] Embodiment 2:

[0070] The data synchronization method of this embodiment can be applied to electronic devices with communication, computing and data storage capabilities. The specific process can be as follows: Figure 3 As shown, the data synchronization method of this embodiment is applied to a message queue server, including:

[0071] Step 301: Receive update information pushed by the main database, and store the update information in a local message queue.

[0072] Specifically, the update information pushed by the master data is encrypted update information to improve data security.

[0073] Step 302, setting a topic for the newly stored update information, and based on the topic of the message subscribed by the message consumer contracted with the message queue server, pushing the newly stored update information to the matching message consumer, so as to synchronize the latest update information to the slave database through the message consumer.

[0074] Specifically, pushing the newly stored update information to the matching message consumer in step 302 includes: pushing the newly stored encrypted update information to the matching message consumer.

[0075] The message queue server is used as the executor of the data synchronization method in this embodiment. The main database and the slave database are connected through the message queue server, so that the update information pushed from the main database is received in the message queue server, and then the update message is pushed to the matching message consumer. The latest update information can be synchronized to the slave database through the message consumer, and the update data synchronization of the slave database is completed in real time, which enhances the security of data information and ensures the consistency of data between multiple databases. The efficient asynchronous communication mechanism of the message queue is utilized to improve the timeliness of data synchronization and the synchronization efficiency.

[0076] Furthermore, in the present embodiment, an initial expiration time and a push mark are set for the update information in the data table. After the message queue server receives the update information pushed by the main database, the initial expiration time and the push mark of the update information recorded in the data table are updated in the main database, so that the initial expiration time can be used to regularly delete the content in the data table to avoid the update information being retained in the data table after the update is completed, resulting in excessive storage pressure. At the same time, the push mark can be used to mark whether the push of each update information in the data table is successful, so that the update information that has not been pushed can be accurately pushed to the message queue, which is conducive to accurately pushing messages and improving the accuracy and stability of synchronous updating of update information.

[0077] Embodiment three:

[0078] The data synchronization method of this embodiment can be applied to electronic devices with communication, computing and data storage capabilities. The specific process can be as follows: Figure 4 As shown, the data synchronization method of this embodiment is applied to a message consumer, including:

[0079] Step 401: Based on the subject of the message subscribed to by the message queue server, monitor and obtain the latest update information from the message queue server, wherein the latest update information is the update information that the master database has pushed to the message queue server, and the latest update information is the update information generated when the master database is updated;

[0080] Specifically, the message consumer is configured with one or more, which are set corresponding to the number of slave databases, so that the message consumer is configured with the connection information with the message queue server. Based on the subject of the message subscribed to the message queue server, the message consumer can monitor and obtain the latest update information from the message queue server, and then use the update information to update the slave database.

[0081] Step 402: Synchronize the latest update information to the slave database, so that the slave database completes synchronization of update data with the master database.

[0082] In some embodiments, the latest update information monitored and obtained from the message queue server in step 401 is an encrypted update message;

[0083] In step 402, synchronizing the latest update information to the slave database includes:

[0084] The latest encrypted update message monitored and obtained from the message queue server is decrypted, and the decrypted latest update information is synchronized to the slave database.

[0085] The execution subject of the data synchronization method in this embodiment is a message consumer, which can monitor and obtain the latest update information from the message queue by subscription, so as to synchronize the updated data of the slave database through the update information. By corresponding to the slave database through the message consumer, the effect of synchronizing the updated data of multiple slave databases can be met, the timeliness of data synchronization is improved, and the synchronization efficiency is improved. At the same time, combined with the form of encryption, the security of the data update process can be improved to avoid the leakage of updated data.

[0086] Furthermore, in the present embodiment, an initial expiration time and a push mark are set for the update information in the data table. In the present embodiment, after the message queue server receives the update information pushed by the main database, the initial expiration time and the push mark of the update information recorded in the data table are updated in the main database, so that the initial expiration time can be used to regularly delete the content in the data table to avoid the update information being retained in the data table after the update is completed, resulting in excessive storage pressure; at the same time, the push mark can be used to mark whether the push of each update information in the data table is successful, so that the update information that has not been pushed can be accurately pushed to the message queue, which is conducive to accurately pushing messages and improving the accuracy and stability of synchronous updating of update information.

[0087] Embodiment 4:

[0088] The data synchronization method of this embodiment can be applied to electronic devices with communication, computing and data storage capabilities. The specific process can be as follows: Figure 5 As shown, the data synchronization method of this embodiment is applied to a slave database, including:

[0089] Step 501: Receive the latest update information pushed by the message consumer from the message queue server and obtain the latest update information, the latest update information is the update information pushed to the message queue server by the master database, and the latest update information is the update information generated when the master database is updated;

[0090] Step 502: Generate a database statement for the received update information, and execute the database statement in the slave database to complete synchronization of the update data with the master database.

[0091] In this embodiment, the executor of the data synchronization method is the slave database, so that the slave database can combine with the message consumer and the message queue server to establish a data synchronization update connection with the master database, thereby utilizing the efficient asynchronous communication mechanism of the message queue to improve the timeliness of data synchronization and improve synchronization efficiency.

[0092] Furthermore, in the present embodiment, an initial expiration time and a push mark are set for the update information in the data table of the main database. In the present embodiment, after the message queue server receives the update information pushed by the main database, the initial expiration time and the push mark of the update information recorded in the data table are updated in the main database, so that the initial expiration time can be used to regularly delete the content in the data table to avoid the update information being retained in the data table after the update is completed, resulting in excessive storage pressure; at the same time, the push mark can be used to mark whether the push of each update information in the data table is successful, so that the update information that has not been pushed can be accurately pushed to the message queue, which is conducive to accurately pushing messages and improving the accuracy and stability of synchronous updating of update information.

[0093] Embodiment five:

[0094] Another embodiment of the present application relates to a data synchronization system. The implementation details of the data synchronization system of this embodiment are described in detail below. The following content is only for the convenience of understanding the implementation details, and is not necessary for the implementation of this solution. The schematic diagram of the data synchronization system of this embodiment can be as follows Figure 6 As shown, it includes a master database 801, at least one slave database 802, a message queue server 803, and at least one message consumer 804. Specifically:

[0095] The main database 801 is used to insert update information corresponding to the updated data into a data table located in the main database when data is updated in the main database, and push the update information inserted in the data table to a message queue server;

[0096] The message queue server 802 is used to receive the update information pushed by the master database, store the update information in a local message queue, and set a topic for the newly stored update information;

[0097] A message consumer 803 is used to monitor and obtain the latest update information from the message queue server based on the subject of the message subscribed to the message queue server, and synchronize the latest update information to the slave database;

[0098] The slave database 804 is used to receive update information pushed by the message consumer, generate database statements for the received update information, and execute the database statements to complete synchronization of update data with the master database.

[0099] In this embodiment, the master database is connected to the message queue server, the message consumers correspond to the slave databases one by one, and the message consumers are configured with the connection information of the message queue server to subscribe to the messages of the corresponding message queue.

[0100] It is worth mentioning that all modules involved in this embodiment are logic modules. In practical applications, a logic unit can be a physical unit, a part of a physical unit, or a combination of multiple physical units. In addition, in order to highlight the innovative part of this application, this embodiment does not introduce units that are not closely related to solving the technical problems proposed by this application, but this does not mean that there are no other units in this embodiment.

[0101] Embodiment six:

[0102] Another embodiment of the present application relates to an electronic device, such as Figure 7As shown, it includes: at least one processor 901; and a memory 902 that is communicatively connected to the at least one processor 901; wherein the memory 902 stores instructions that can be executed by the at least one processor 901, and the instructions are executed by the at least one processor 901 so that the at least one processor 901 can execute the data synchronization method in the above-mentioned embodiments.

[0103] Among them, the memory and the processor are connected in a bus manner, and the bus may include any number of interconnected buses and bridges, and the bus connects various circuits of one or more processors and memories together. The bus can also connect various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. The bus interface provides an interface between the bus and the transceiver. The transceiver can be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. The data processed by the processor is transmitted on a wireless medium via an antenna, and further, the antenna also receives data and transmits the data to the processor.

[0104] The processor is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory can be used to store data used by the processor when performing operations.

[0105] Embodiment seven:

[0106] Another embodiment of the present application relates to a computer-readable storage medium, such as Figure 8 As shown, a computer program 31 is stored, and when the computer program 31 is executed by a processor, the above method embodiment is implemented.

[0107] That is, those skilled in the art can understand that all or part of the steps in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a program, and the program is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, referred to as: ROM), random access memory (Random Access Memory, referred to as: RAM), disk or optical disk and other media that can store program codes.

[0108] Those skilled in the art will appreciate that the above embodiments are specific embodiments for implementing the present application, and in actual applications, various changes may be made thereto in form and detail without departing from the spirit and scope of the present application.

Claims

1. A data synchronization method, characterized in that: Applied to the main database, including: When data in the master database is updated, update information corresponding to the updated data is inserted into a data table located in the master database; The newly inserted update information is read from the data table, and the read update information is pushed to the message queue server, so that the message consumer can monitor and obtain the latest update information from the message queue server, and synchronize the latest update information to the slave database, so that the slave database completes the update data synchronization.

2. A data synchronization method according to claim 1, characterized in that: After inserting the update information into the data table located in the main database, the method further includes: Setting an initial expiration time and a push mark for the update information newly inserted into the data table, wherein the starting time point of the initial expiration time is the time point corresponding to when the update information is inserted into the data table, and the push mark is set to not pushed by default; After successfully pushing the read update information to the message queue server, it also includes: The starting time point of the initial expiration time corresponding to the successfully pushed update information is updated to the time point corresponding to when the update information is successfully pushed, and the push mark corresponding to the successfully pushed update information is updated to pushed.

3. A data synchronization method according to claim 2, characterized in that: When data update occurs in the main database, inserting update information into a data table located in the main database comprises: When data in the main database is updated, a prefabricated trigger is triggered to automatically insert the update information into a data table in the main database.

4. A data synchronization method according to claim 1, characterized in that: The step of pushing the read update information to the message queue server includes: The read update information is encrypted and pushed to the message queue server.

5. A data synchronization method, characterized in that: Applicable to message queue servers, including: Receive update information pushed by the master database and store the update information in the local message queue; A topic is set for the newly stored update information, and based on the topic of the message subscribed by the message consumer contracted with the message queue server, the newly stored update information is pushed to the matching message consumer, so that the latest update information is synchronized to the slave database through the message consumer.

6. The data synchronization method according to claim 5, characterized in that: The update information pushed by the master database is encrypted update information; The storing the update information in the local message queue comprises: storing the encrypted update information in the local message queue; The pushing of the newly stored update information to the matching message consumer includes: pushing the newly stored encrypted update information to the matching message consumer.

7. A data synchronization method, characterized in that: Applicable to message consumers, including: Based on the subject of the message subscribed to by the message queue server, the latest update information is monitored and obtained from the message queue server, where the latest update information is the update information that the master database has pushed to the message queue server, and the latest update information is the update information generated when the master database is updated; The latest update information is synchronized to the slave database, so that the slave database completes the synchronization of update data with the master database.

8. The data synchronization method according to claim 7, characterized in that: The latest update information monitored and obtained from the message queue server is an encrypted update message; The step of synchronizing the latest update information to the slave database includes: The latest encrypted update message monitored and obtained from the message queue server is decrypted, and the decrypted latest update information is synchronized to the slave database.

9. A data synchronization method, characterized in that: Applied to the slave database, including: The receiving message consumer listens to and obtains the latest update information from the message queue server, wherein the latest update information is the update information that the master database has pushed to the message queue server, and the latest update information is the update information generated when the master database is updated; A database statement is generated for the received update information, and the database statement is executed in the slave database to complete synchronization of the update data with the master database.

10. A data synchronization system, characterized in that: include: A master database, at least one slave database, a message queue server, and at least one message consumer; The master database is used to insert update information corresponding to the updated data into a data table located in the master database when data is updated in the master database, and push the update information inserted in the data table to a message queue server; The message queue server is used to receive the update information pushed by the main database, store the update information in a local message queue, and set a topic for the newly stored update information; The message consumer is used to monitor and obtain the latest update information from the message queue server based on the subject of the message subscribed to the message queue server, and synchronize the latest update information to the slave database; The slave database is used to receive update information pushed by the message consumer, generate database statements for the received update information, and execute the database statements to complete synchronization of update data with the master database.

11. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the data synchronization method as described in any one of claims 1 to 9.

12. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the data synchronization method according to any one of claims 1 to 9 is implemented.