WO2020248375A1 - Method and system for synchronizing data between databases, computer device and storage medium - Google Patents

Method and system for synchronizing data between databases, computer device and storage medium Download PDF

Info

Publication number
WO2020248375A1
WO2020248375A1 PCT/CN2019/102843 CN2019102843W WO2020248375A1 WO 2020248375 A1 WO2020248375 A1 WO 2020248375A1 CN 2019102843 W CN2019102843 W CN 2019102843W WO 2020248375 A1 WO2020248375 A1 WO 2020248375A1
Authority
WO
WIPO (PCT)
Prior art keywords
data
synchronization
operation instruction
incremental
sql statement
Prior art date
Application number
PCT/CN2019/102843
Other languages
French (fr)
Chinese (zh)
Inventor
刘益伟
杨茂星
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2020248375A1 publication Critical patent/WO2020248375A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/273Asynchronous replication or reconciliation

Definitions

  • the embodiments of the present application relate to the field of data processing technology, and in particular, to a method, system, computer device, and storage medium for data synchronization between databases.
  • the purpose of the embodiments of the present application is to provide a data synchronization method, system, computer device, and non-volatile computer-readable storage medium between databases, which can increase the scalability of the system and reduce development costs.
  • an embodiment of the present application provides a data synchronization method between databases, which includes the following steps:
  • an embodiment of the present application also provides a computer device, including a memory, a processor, and computer-readable instructions stored in the memory and running on the processor, and the processor executes the computer-readable instructions.
  • the steps of the method for data synchronization between databases as described above are implemented when instructed.
  • the embodiments of the present application also provide a non-volatile computer-readable storage medium.
  • the non-volatile computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions may Is executed by at least one processor, so that the at least one processor executes the steps of the method for data synchronization between databases as described above.
  • the method, system, computer equipment, and non-volatile computer-readable storage medium for data synchronization between databases acquire data operation instructions and analyze the data operation instructions to obtain the data operation instructions.
  • the table name of the included data table, the data operation instruction is an instruction based on the SQL statement; it is judged whether there is a data table matching the table name in the preset synchronization record table; if it exists, the record is based on the data
  • the incremental data generated by the data processing service executed by the operation instruction; and the incremental data is periodically synchronized to the target database, so that the scalability of the system can be increased and the development cost can be reduced.
  • FIG. 1 is a schematic diagram of the implementation process of the first embodiment of the data synchronization method between databases of this application.
  • FIG. 2 is a detailed flow diagram of the steps of obtaining data operation instructions in this application and analyzing the data operation instructions to obtain the table names of the data tables included in the data operation instructions.
  • FIG. 3 is a detailed flow diagram of the step of synchronizing the incremental data to the target database regularly in this application.
  • FIG. 4 is a schematic diagram of the implementation process of the second embodiment of the method for data synchronization between databases of this application.
  • FIG. 5 is a schematic diagram of program modules of a data synchronization system between databases according to an embodiment of this application.
  • FIG. 6 is a schematic diagram of the hardware structure of a computer device according to an embodiment of the application.
  • FIG. 1 shows a flowchart of a method for data synchronization between databases in the first embodiment of the present application. It can be understood that the flowchart in this method embodiment is not used to limit the order of execution of the steps.
  • the following is an exemplary description with an inter-database data synchronization system (hereinafter referred to as “synchronization system” for short) as the execution subject, and the synchronization system can be applied to computer equipment. details as follows:
  • Step S100 Obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction.
  • the data operation instruction is an instruction based on a SQL statement.
  • the synchronization system may obtain data operation instructions sent by the user equipment, and the data operation instructions may include data addition instructions, data deletion instructions, data modification instructions, and so on. After receiving the data operation instruction, the synchronization system may further execute data processing services according to the data operation instructions.
  • the data processing services may include data addition services, data deletion services, data modification services, etc. to the database. For example, if the data operation instruction is a data modification instruction, the synchronization system modifies the corresponding data in the database according to the data modification instruction.
  • the synchronization system can also parse the data operation instruction to obtain the data table information involved in the data operation instruction.
  • the data table information includes the table name of the data table. .
  • the data operation instruction in the embodiment of the present application is an instruction based on a SQL (Structured Query Language) statement, that is, the data operation instruction is an SQL statement.
  • SQL Structured Query Language
  • the step of obtaining a data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction includes:
  • Step S200 intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction;
  • Step S202 parse the SQL statement to extract the table name of the data table included in the SQL statement.
  • the synchronization system can call the mybtis interceptor to intercept the data operation instruction, thereby capturing the SQL statement in the data operation instruction. After the SQL statement is captured, the SQL statement can be further analyzed to extract the SQL statement
  • the data table information includes the table name of the data table.
  • the mybtis interceptor when the table name of the data table contained in the data operation instruction does not need to be obtained, the mybtis interceptor can be shielded.
  • Step S102 Determine whether there is a data table matching the table name in the preset synchronization record table.
  • the synchronization record table is a data table that needs to be synchronized in each data table of the source database.
  • the synchronization record table can be set according to business requirements. For example, if the current business requirement is to synchronize the modified data in data table A and data table B in the source database, the synchronization record table can be set to include Data table A and data table B, that is, only the modified data in data table A and data table B need to be synchronized in the future, and the data in other data tables does not need to be synchronized; if the current business requirement is to synchronize the source database , You can set the synchronization record table to include all data tables in the source database, that is, as long as the data in the source database is modified subsequently, the modified data must be synchronized.
  • the obtained table name and the table name of each data table contained in the synchronization record table can be compared with the obtained table name one by one to determine whether the synchronization record table exists and The data table whose table name matches.
  • Step S104 if it exists, record the incremental data generated by the data processing service executed according to the data operation instruction.
  • the incremental data includes the SQL statement corresponding to the data operation instruction and the data table information, database information, etc. involved in the SQL statement.
  • Step S106 Synchronize the incremental data to the target database regularly.
  • the synchronization system regularly synchronizes incremental data to the target database, for example, synchronizes all incremental data to the target database every 1 minute.
  • the target database is the database to which the data in the source database is to be synchronized, and there may be multiple target databases, for example, database A, database B, database C, and so on.
  • the SQL statement contained in the incremental data can be executed in the target database, thereby achieving data synchronization.
  • the address of the target database needs to be maintained in the source database in advance.
  • the method for data synchronization between databases proposed in this embodiment of the application obtains data operation instructions and parses the data operation instructions to obtain the table name of the data table included in the data operation instruction. It is an instruction based on SQL statement; it is determined whether there is a data table matching the table name in the preset synchronization record table; if it exists, it records the incremental data generated by the data processing service executed according to the data operation instruction ; And regularly synchronize the incremental data to the target database, which can increase the scalability of the system and reduce development costs.
  • the step of periodically synchronizing the incremental data to the target database includes:
  • Step S300 Determine the incremental data that currently needs to be synchronized.
  • the incremental data recorded in this synchronization cycle is 15:12:10
  • the time stamp of this synchronization cycle is 15:13:10, it is between 15:12:10 and 15:13:10
  • the incremental data recorded in the time period is the incremental data that needs to be synchronized currently.
  • Step S302 Obtain the first data table associated with each incremental data.
  • each incremental data is associated with a first data table, and the first data table associated with different incremental data may be the same or different.
  • Step S304 Determine the address information of the target database corresponding to each incremental data according to the first data table.
  • each first data table may correspond to one target database, or may correspond to multiple target databases.
  • data table a corresponds to target database B
  • data table b corresponds to target database C and target database D, and so on.
  • Step S306 Synchronize each incremental data to the corresponding target database according to the address information.
  • the synchronization system can synchronize the incremental data to the corresponding target database through the address of the target server.
  • the method further includes:
  • the target database executes the SQL statement in the incremental data, thereby achieving data synchronization.
  • the target database performs the data synchronization operation, it will feed back a data synchronization result to the synchronization system.
  • the synchronization system parses the synchronization result, and then can determine that the target database is checking the data according to the parsed synchronization result Whether the data synchronization was successfully completed during synchronization.
  • identification information for the incremental data that has been synchronized, such as setting the “complete” flag or the “1” flag to Indicates that the incremental data has completed data synchronization.
  • the target database after the target database receives the incremental data, it continuously executes the SQL statement in the incremental data several times (for example, 3 times), and the data synchronization is still not achieved, then the synchronization can be fed back
  • the failed synchronization result is sent to the synchronization system.
  • the synchronization system After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine whether the target database successfully completes the data synchronization when synchronizing the data according to the parsed synchronization result.
  • a notification message is sent to the preset user.
  • the notification message can be sent by email or by SMS.
  • the preset user is preferably a maintenance person of the target server.
  • the synchronized incremental data when the data synchronization of the incremental data is successfully completed, the synchronized incremental data may be stored in the historical data table as a record. In this embodiment, by storing the successfully synchronized incremental data in the historical data table, it is convenient to troubleshoot the problem based on the data in the historical data table when a problem occurs later.
  • FIG. 4 is a schematic diagram of the implementation process of the second embodiment of the data synchronization method between databases of the present application.
  • the execution order of the steps in the flowchart shown in FIG. 4 can be changed, and some steps can be omitted.
  • the following exemplarily describes an inter-database data synchronization system (hereinafter referred to as “synchronization system” for short) as the execution subject, and the synchronization system can be applied to a server. details as follows:
  • Step S400 Set a data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
  • the data record range corresponding to the data processing service can be set according to business requirements, and the data record range is specifically which data tables in the source database need to be synchronized.
  • the data recording range can be set in advance, or can be set later based on user input information. For example, if the user needs to synchronize the data table a in the source database, the user can input the information corresponding to the data table a to the synchronization system. After receiving the input information, the synchronization system sets the data table a according to the input information. Data logging range.
  • Step S402 Obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction.
  • the data operation instruction is an instruction based on a SQL statement.
  • Step S404 Determine whether there is a data table matching the table name in the preset synchronization record table
  • Step S406 if it exists, record the incremental data generated by the data processing service executed according to the data operation instruction.
  • Step S408 Synchronize the incremental data to the target database regularly.
  • steps S402-S408 are similar to steps S100-S106, and will not be repeated in this embodiment.
  • the system has good scalability.
  • FIG. 5 shows a schematic diagram of program modules of an inter-database data synchronization system 500 (hereinafter referred to as "synchronization system” 500) according to an embodiment of the present application.
  • the synchronization system 500 may include or be divided into one or more program modules, and the one or more program modules are stored in a storage medium and executed by one or more processors to complete the application , And can realize the above-mentioned data synchronization method between databases.
  • the program module referred to in the embodiments of the present application refers to an instruction segment of a series of computer-readable instructions capable of completing specific functions, and is more suitable for describing the execution process of the data synchronization method between databases in the storage medium than the program itself. The following description will specifically introduce the functions of each program module in this embodiment:
  • the obtaining module 501 is configured to obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction, and the data operation instruction is an instruction based on a SQL statement.
  • the obtaining module 501 may obtain a data operation instruction sent by a user equipment, and the data operation instruction may include a data addition instruction, a data deletion instruction, a data modification instruction, and so on. After receiving the data operation instruction, the acquisition module 501 may further execute data processing services according to the data operation instructions.
  • the data processing services may include data addition services, data deletion services, data modification services, etc., to the database. For example, if the data operation instruction is a data modification instruction, the acquisition module 501 modifies the corresponding data in the database according to the data modification instruction.
  • the acquisition module 501 can also parse the data operation instruction to obtain the data table information involved in the data operation instruction.
  • the data table information includes the table of the data table. name.
  • the data operation instruction in the embodiment of the present application is an instruction based on a SQL (Structured Query Language) statement, that is, the data operation instruction is an SQL statement.
  • SQL Structured Query Language
  • the step of obtaining the data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction includes: checking all the data through the mybtis interceptor. The data operation instruction is intercepted, and the SQL statement in the data operation instruction is obtained; and used to parse the SQL statement to extract the table name of the data table contained in the SQL statement.
  • the acquisition module 501 can call the mybtis interceptor to intercept the data operation instruction, thereby capturing the SQL statement in the data operation instruction. After the SQL statement is captured, the SQL statement can be further parsed to extract the SQL statement The data table information in the data table information contains the table name of the data table.
  • the mybtis interceptor when the table name of the data table contained in the data operation instruction does not need to be obtained, the mybtis interceptor can be shielded.
  • the judging module 502 is configured to judge whether there is a data table matching the table name in the preset synchronization record table.
  • the synchronization record table is a data table that needs to be synchronized in each data table of the source database.
  • the synchronization record table can be set according to business requirements. For example, if the current business requirement is to synchronize the modified data in data table A and data table B in the source database, the synchronization record table can be set to include Data table A and data table B, that is, only the modified data in data table A and data table B need to be synchronized in the future, and the data in other data tables does not need to be synchronized; if the current business requirement is to synchronize the source database , You can set the synchronization record table to include all data tables in the source database, that is, as long as the data in the source database is modified subsequently, the modified data must be synchronized.
  • the obtained table name and the table name of each data table contained in the synchronization record table can be compared with the obtained table name one by one to determine whether the synchronization record table exists and The data table whose table name matches.
  • the recording module 503 is configured to record the incremental data generated by the data processing service executed according to the data operation instruction when there is a data table matching the table name.
  • the recording module 503 needs to record the incremental data generated by the data processing service executed according to the data operation instruction.
  • the incremental data includes the SQL statement corresponding to the data operation instruction and the data table information, database information, etc. involved in the SQL statement.
  • the synchronization module 504 is configured to periodically synchronize the incremental data to the target database.
  • the synchronization module 504 periodically synchronizes the incremental data to the target database, for example, synchronizes all the incremental data to the target database every 1 minute.
  • the target database is the database to which the data in the source database is to be synchronized, and there may be multiple target databases, for example, database A, database B, database C, etc.
  • the SQL statement contained in the incremental data can be executed in the target database, thereby achieving data synchronization.
  • the address of the target database needs to be maintained in the source database in advance.
  • the data synchronization system between databases proposed in this embodiment of the application obtains the data operation instruction and parses the data operation instruction to obtain the table name of the data table included in the data operation instruction. It is an instruction based on SQL statement; it is determined whether there is a data table matching the table name in the preset synchronization record table; if it exists, it records the incremental data generated by the data processing service executed according to the data operation instruction ; And regularly synchronize the incremental data to the target database, which can increase the scalability of the system and reduce development costs.
  • the step of periodically synchronizing the incremental data to the target database includes:
  • Step 1 Determine the incremental data that currently needs to be synchronized.
  • the incremental data recorded in this synchronization cycle is 15:12:10
  • the time stamp of this synchronization cycle is 15:13:10, it is between 15:12:10 and 15:13:10
  • the incremental data recorded in the time period is the incremental data that needs to be synchronized currently.
  • Step 2 Obtain the first data table associated with each incremental data.
  • each incremental data is associated with a first data table, and the first data table associated with different incremental data may be the same or different.
  • Step 3 Determine the address information of the target database corresponding to each incremental data according to the first data table.
  • each first data table may correspond to one target database, or may correspond to multiple target databases.
  • data table a corresponds to target database B
  • data table b corresponds to target database C and target database D, and so on.
  • Step 4 Synchronize each incremental data to the corresponding target database according to the address information.
  • the synchronization system can synchronize the incremental data to the corresponding target database through the address of the target server.
  • the method further includes:
  • the target database executes the SQL statement in the incremental data, thereby achieving data synchronization.
  • the target database performs the data synchronization operation, it will feed back a data synchronization result to the synchronization system.
  • the synchronization system parses the synchronization result, and then can determine that the target database is checking the data according to the parsed synchronization result Whether the data synchronization was successfully completed during synchronization.
  • identification information for the incremental data that has been synchronized, such as setting the “complete” flag or the “1” flag to Indicates that the incremental data has completed data synchronization.
  • the target database after the target database receives the incremental data, it continuously executes the SQL statement in the incremental data several times (for example, 3 times), and the data synchronization is still not achieved, then the synchronization can be fed back
  • the failed synchronization result is sent to the synchronization system.
  • the synchronization system After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine whether the target database successfully completes the data synchronization when synchronizing the data according to the parsed synchronization result.
  • a notification message is sent to the preset user.
  • the notification message can be sent by email or by SMS.
  • the preset user is preferably a maintenance person of the target server.
  • the synchronized incremental data when the data synchronization of the incremental data is successfully completed, the synchronized incremental data may be stored in the historical data table as a record. In this embodiment, by storing the successfully synchronized incremental data in the historical data table, it is convenient to troubleshoot the problem based on the data in the historical data table when a problem occurs later.
  • the synchronization system 500 further includes:
  • the setting module is used to set the data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
  • the data record range corresponding to the data processing service can be set according to business requirements, and the data record range is specifically which data tables in the source database need to be synchronized.
  • the data recording range can be set in advance, or can be set later based on user input information. For example, if the user needs to synchronize the data table a in the source database, the user can input the information corresponding to the data table a into the setting module of the synchronization system. After receiving the input information, the setting module will use the input information Set the data recording range.
  • FIG. 6 is a schematic diagram of the hardware architecture of a computer device 600 according to an embodiment of the present application.
  • the computer device 600 is a device that can automatically perform numerical calculation and/or information processing according to pre-set or stored instructions.
  • the computer device 600 at least includes, but is not limited to, a memory 601, a processor 602, a network interface 603, and a data synchronization system 604 between databases that can communicate with each other through a system bus. among them:
  • the memory 601 includes at least one type of non-volatile computer-readable storage medium.
  • the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), Random access memory (RAM), static random access memory (SRAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disk, optical disk Wait.
  • the memory 601 may be an internal storage unit of the computer device 600, such as a hard disk or memory of the computer device 600.
  • the memory 601 may also be an external storage device of the computer device 600, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), and a secure digital (Secure Digital, SD) card, flash card (Flash Card), etc.
  • the memory 601 may also include both the internal storage unit of the computer device 600 and its external storage device.
  • the memory 601 is generally used to store the operating system and various application software installed in the computer device 600, such as the program code of the data synchronization system 604 between databases.
  • the memory 601 can also be used to temporarily store various types of data that have been output or will be output.
  • the processor 602 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments.
  • the processor 602 is generally used to control the overall operation of the computer device 600.
  • the processor 602 is configured to run the program code or process data stored in the memory 601, for example, to run the inter-database data synchronization system 604 to implement the inter-database data synchronization method in each of the foregoing embodiments.
  • the network interface 603 may include a wireless network interface or a wired network interface, and the network interface 603 is generally used to establish a communication connection between the computer device 600 and other electronic devices.
  • the network interface 603 is used to connect the computer device 600 to an external terminal through a network, and to establish a data transmission channel and a communication connection between the computer device 600 and the external terminal.
  • the network may be an intranet (Intranet), the Internet (Internet), a global system of mobile communications (Global System of Mobile) communication, GSM), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), 4G network, 5G network, Bluetooth (Bluetooth), Wi-Fi and other wireless or wired networks.
  • FIG. 6 only shows a computer device 600 with components 601-604, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead.
  • the inter-database data synchronization system 604 stored in the memory 601 can also be divided into one or more program modules, and the one or more program modules are stored in the memory 601 and consist of one Or executed by multiple processors (processor 602 in this embodiment) to complete the data synchronization method between databases of this application.
  • This embodiment also provides a non-volatile computer-readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory ( SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, server, App application mall, etc., on which storage There are computer-readable instructions, and the corresponding functions are realized when the program is executed by the processor.
  • the non-volatile computer-readable storage medium of this embodiment is used to store the inter-database data synchronization system 500 or 604, so as to implement the following steps when executed by a processor:

Abstract

Provided in the embodiments of the present application is a method for synchronizing data between databases. The method comprises the following steps: by means of acquiring a data operation instruction and parsing the data operation instruction, obtaining a table name of a data table included in the data operation instruction, wherein the data operation instruction is an SQL sentence-based instruction; determining whether a data table matching the table name exists in a preset synchronizing record table; if the data table matching the table name exists in the preset synchronizing record table, recording incremental data generated by a data processing service executed according to the data operation instruction; and regularly synchronizing the incremental data to a target database. Further provided in the embodiments of the present application are a system for synchronizing data between databases, a computer device and a non-volatile computer storage medium. The embodiments of the present application can improve the extensibility of a system and reduce the development cost.

Description

数据库间数据同步方法、系统、计算机设备及存储介质Data synchronization method, system, computer equipment and storage medium between databases
本申请要求于2019年6月14日提交中国专利局、申请号为201910513290.2、发明名称为“数据库间数据同步方法、系统、计算机设备及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application filed with the Chinese Patent Office on June 14, 2019, the application number is 201910513290.2, and the invention title is "Data synchronization method, system, computer equipment and storage medium between databases". The reference is incorporated in this application.
技术领域Technical field
本申请实施例涉及数据处理技术领域,尤其涉及一种数据库间数据同步方法、系统、计算机设备及存储介质。The embodiments of the present application relate to the field of data processing technology, and in particular, to a method, system, computer device, and storage medium for data synchronization between databases.
背景技术Background technique
现有技术中,在实现各个系统之间数据同步时,一般是通过定制开发系统间要同步的表的来实现系统之间的同步。然而,发明人意识到当某个系统需要同多个其他系统进行数据同步时,则需要定制开发多个系统间要同步的表来实现该系统与多个系统之间的数据同步,该实现方法繁琐,灵活度不够。In the prior art, when realizing data synchronization between various systems, the synchronization between systems is generally achieved by customizing and developing tables to be synchronized between the systems. However, the inventor realized that when a system needs to synchronize data with multiple other systems, it is necessary to customize and develop tables to be synchronized between multiple systems to achieve data synchronization between the system and multiple systems. This implementation method Trivial and insufficient flexibility.
发明内容Summary of the invention
有鉴于此,本申请实施例的目的是提供一种数据库间数据同步方法、系统、计算机设备及非易失性计算机可读存储介质,能够增加系统的可扩展性,降低开发成本。In view of this, the purpose of the embodiments of the present application is to provide a data synchronization method, system, computer device, and non-volatile computer-readable storage medium between databases, which can increase the scalability of the system and reduce development costs.
为实现上述目的,本申请实施例提供了一种数据库间数据同步方法,包括以下步骤:To achieve the foregoing objective, an embodiment of the present application provides a data synchronization method between databases, which includes the following steps:
获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;Acquiring a data operation instruction, and analyzing the data operation instruction to obtain a table name of a data table included in the data operation instruction, where the data operation instruction is an instruction based on a SQL statement;
判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Judging whether there is a data table matching the table name in the preset synchronization record table;
若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及If it exists, record the incremental data generated by the data processing service executed according to the data operation instruction; and
定时将所述增量数据同步至目标数据库。Synchronize the incremental data to the target database regularly.
为实现上述目的,本申请实施例还提供了一种计算机设备,包括存储器、处理器以及存储在存储器上并可在处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时实现如上所述数据库间数据同步方法的步骤。To achieve the foregoing objective, an embodiment of the present application also provides a computer device, including a memory, a processor, and computer-readable instructions stored in the memory and running on the processor, and the processor executes the computer-readable instructions. The steps of the method for data synchronization between databases as described above are implemented when instructed.
为实现上述目的,本申请实施例还提供了一种非易失性计算机可读存储介质,所述非易失性计算机可读存储介质内存储有计算机可读指令,所述计算机可读指令可被至少一个处理器所执行,以使所述至少一个处理器执行如上所述的数据库间数据同步方法的步骤。In order to achieve the above objective, the embodiments of the present application also provide a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions may Is executed by at least one processor, so that the at least one processor executes the steps of the method for data synchronization between databases as described above.
本申请实施例提供的数据库间数据同步方法、系统、计算机设备及非易失性计算机可读存储介质,通过获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;判断预设的同步记录表中是否存在与所述表名相匹配的数据表;若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及定时将所述增量数据同步至目标数据库,从而能够增加系统的可扩展性,降低开发成本。The method, system, computer equipment, and non-volatile computer-readable storage medium for data synchronization between databases provided by the embodiments of the present application acquire data operation instructions and analyze the data operation instructions to obtain the data operation instructions. The table name of the included data table, the data operation instruction is an instruction based on the SQL statement; it is judged whether there is a data table matching the table name in the preset synchronization record table; if it exists, the record is based on the data The incremental data generated by the data processing service executed by the operation instruction; and the incremental data is periodically synchronized to the target database, so that the scalability of the system can be increased and the development cost can be reduced.
附图说明Description of the drawings
图1为本申请数据库间数据同步方法第一实施例的实施流程示意图。FIG. 1 is a schematic diagram of the implementation process of the first embodiment of the data synchronization method between databases of this application.
图2为本申请中获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名的步骤细化流程示意图。FIG. 2 is a detailed flow diagram of the steps of obtaining data operation instructions in this application and analyzing the data operation instructions to obtain the table names of the data tables included in the data operation instructions.
图3为本申请中定时将所述增量数据同步至目标数据库的步骤的细化流程示意图。FIG. 3 is a detailed flow diagram of the step of synchronizing the incremental data to the target database regularly in this application.
图4为本申请数据库间数据同步方法第二实施例的实施流程示意图。4 is a schematic diagram of the implementation process of the second embodiment of the method for data synchronization between databases of this application.
图5为本申请一实施方式的数据库间数据同步系统的程序模块示意图。FIG. 5 is a schematic diagram of program modules of a data synchronization system between databases according to an embodiment of this application.
图6为本申请一实施方式的计算机设备的硬件结构示意图。FIG. 6 is a schematic diagram of the hardware structure of a computer device according to an embodiment of the application.
具体实施方式Detailed ways
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅用以解释本申请,并不用于限定本申请。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。In order to make the purpose, technical solutions, and advantages of this application clearer, the following further describes this application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the application, and not used to limit the application. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of this application.
参阅图1,示出了本申请实施例一之数据库间数据同步方法的流程图。可以理解,本方法实施例中的流程图不用于对执行步骤的顺序进行限定。下面以数据库间数据同步系统(下文以“同步系统”简称)为执行主体进行示例性描述,所述同步系统可以应用于计算机设备中。具体如下:Referring to FIG. 1, it shows a flowchart of a method for data synchronization between databases in the first embodiment of the present application. It can be understood that the flowchart in this method embodiment is not used to limit the order of execution of the steps. The following is an exemplary description with an inter-database data synchronization system (hereinafter referred to as “synchronization system” for short) as the execution subject, and the synchronization system can be applied to computer equipment. details as follows:
步骤S100,获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令。Step S100: Obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction. The data operation instruction is an instruction based on a SQL statement.
具体地,同步系统可以获取用户设备发送的数据操作指令,所述数据操作指令可以包括数据新增指令、数据删除指令、数据修改指令等等。同步系统在接收到数据操作指令之后,可进一步根据所述数据操作指令执行数据处理业务,所述数据处理业务可以包括对数据库进行数据新增业务、数据删除业务、数据修改业务等。例如,若所述数据操作指令为数据修改指令,则所述同步系统根据所述数据修改指令对数据库中的相应是数据进行修改。Specifically, the synchronization system may obtain data operation instructions sent by the user equipment, and the data operation instructions may include data addition instructions, data deletion instructions, data modification instructions, and so on. After receiving the data operation instruction, the synchronization system may further execute data processing services according to the data operation instructions. The data processing services may include data addition services, data deletion services, data modification services, etc. to the database. For example, if the data operation instruction is a data modification instruction, the synchronization system modifies the corresponding data in the database according to the data modification instruction.
在本实施例中,同步系统在接收到数据操作指令之后,也可以对数据操作指令进行解析,从而得到该数据操作指令中所涉及的数据表信息,所述数据表信息包括数据表的表名。In this embodiment, after receiving the data operation instruction, the synchronization system can also parse the data operation instruction to obtain the data table information involved in the data operation instruction. The data table information includes the table name of the data table. .
需要说明的是,本申请实施例中的数据操作指令是基于SQL(Structured Query Language,结构化查询语言)语句的指令,即所述数据操作指令是一条SQL语句。It should be noted that the data operation instruction in the embodiment of the present application is an instruction based on a SQL (Structured Query Language) statement, that is, the data operation instruction is an SQL statement.
进一步地,参阅图2,在一实施例中,所述获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名的步骤包括:Further, referring to FIG. 2, in an embodiment, the step of obtaining a data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction includes:
步骤S200,通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及Step S200, intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction; and
步骤S202,对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。Step S202: parse the SQL statement to extract the table name of the data table included in the SQL statement.
具体地,同步系统可以调用mybtis拦截器对数据操作指令进行拦截,从而捕获数据操作指令中的SQL语句,在捕获到SQL语句后,可以进一步对该SQL语句进行解析,从而提取出该SQL语句中所的数据表信息,该数据表信息中包含有数据表的表名。Specifically, the synchronization system can call the mybtis interceptor to intercept the data operation instruction, thereby capturing the SQL statement in the data operation instruction. After the SQL statement is captured, the SQL statement can be further analyzed to extract the SQL statement The data table information includes the table name of the data table.
在发明实施中,当不需要获取数据操作指令中包含的数据表的表名时,可以将该mybtis拦截器进行屏蔽。In the implementation of the invention, when the table name of the data table contained in the data operation instruction does not need to be obtained, the mybtis interceptor can be shielded.
步骤S102,判断预设的同步记录表中是否存在与所述表名相匹配的数据表。Step S102: Determine whether there is a data table matching the table name in the preset synchronization record table.
具体地,所述同步记录表为源数据库的各个数据表中需要同步的数据表。该同步记录表可以根据业务需求进行设定,例如,当前业务需求为需要对源数据库中的数据表A与数据表B中被修改的数据进行同步,则可以设定所述同步记录表中包括数据表A与数据表B,即后续只需要对数据表A与数据表B中被修改的数据进行同步,对于其他数据表中的数据不需要同步;若当前业务需求为需要对源数据库进行同步,则可以设定所述同步记录表中包括源数据库中的所有数据表,即后续只要源数据库中的数据被修改,都要对修改的数据进行同步。Specifically, the synchronization record table is a data table that needs to be synchronized in each data table of the source database. The synchronization record table can be set according to business requirements. For example, if the current business requirement is to synchronize the modified data in data table A and data table B in the source database, the synchronization record table can be set to include Data table A and data table B, that is, only the modified data in data table A and data table B need to be synchronized in the future, and the data in other data tables does not need to be synchronized; if the current business requirement is to synchronize the source database , You can set the synchronization record table to include all data tables in the source database, that is, as long as the data in the source database is modified subsequently, the modified data must be synchronized.
在具体地判断过程中,可以将获得到的表名与同步记录表中所包含的各个数据表的表名一一与该获得到的表名进行比较,以确定该同步记录表中是否存在与所述表名相匹配的数据表。In the specific judgment process, the obtained table name and the table name of each data table contained in the synchronization record table can be compared with the obtained table name one by one to determine whether the synchronization record table exists and The data table whose table name matches.
步骤S104,若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据。Step S104, if it exists, record the incremental data generated by the data processing service executed according to the data operation instruction.
具体地,当存在与所述表名相匹配的数据表时,表明需要对该数据操作指令所执行的数据处理业务进行同步。因而,在当存在与所述表名相匹配的数据表时,同步系统需要记录根据所述数据操作指令执行的数据处理业务所生成的增量数据。所述增量数据包括所述数据操作指令所对应的SQL语句以及该SQL语句所涉及到的数据表信息、数据库信息等。Specifically, when there is a data table matching the table name, it indicates that the data processing service executed by the data operation instruction needs to be synchronized. Therefore, when there is a data table that matches the table name, the synchronization system needs to record the incremental data generated by the data processing service executed according to the data operation instruction. The incremental data includes the SQL statement corresponding to the data operation instruction and the data table information, database information, etc. involved in the SQL statement.
步骤S106,定时将所述增量数据同步至目标数据库。Step S106: Synchronize the incremental data to the target database regularly.
具体地,同步系统定时会将增量数据同步至目标数据库,比如,每隔1分钟将所有的增量数据同步至目标数据库中。所述目标数据库为要将源数据库中的数据同步至其中的数据库,该目标数据库可以有多个,比如,数据库A、数据库B,数据库C等。Specifically, the synchronization system regularly synchronizes incremental data to the target database, for example, synchronizes all incremental data to the target database every 1 minute. The target database is the database to which the data in the source database is to be synchronized, and there may be multiple target databases, for example, database A, database B, database C, and so on.
在本实施例中,在对增量数据进行同步时,可以在目标数据库中执行该增量数据中所包含的SQL语句,从而实现数据的同步。In this embodiment, when the incremental data is synchronized, the SQL statement contained in the incremental data can be executed in the target database, thereby achieving data synchronization.
可以理解的是,为了将源数据中的增量数据同步至目标数据库中,需要预先将目标数据库的地址维护到源数据库中。It is understandable that in order to synchronize the incremental data in the source data to the target database, the address of the target database needs to be maintained in the source database in advance.
本申请本实施例所提出的数据库间数据同步方法,通过获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;判断预设的同步记录表中是否存在与所述表名相匹配的数据表;若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及定时将所述增量数据同步至目标数据库,从而能够增加系统的可扩展性,降低开发成本。The method for data synchronization between databases proposed in this embodiment of the application obtains data operation instructions and parses the data operation instructions to obtain the table name of the data table included in the data operation instruction. It is an instruction based on SQL statement; it is determined whether there is a data table matching the table name in the preset synchronization record table; if it exists, it records the incremental data generated by the data processing service executed according to the data operation instruction ; And regularly synchronize the incremental data to the target database, which can increase the scalability of the system and reduce development costs.
进一步地,参照图3,在一实施例中,所述定时将所述增量数据同步至目标数据库的步骤包括:Further, referring to FIG. 3, in an embodiment, the step of periodically synchronizing the incremental data to the target database includes:
步骤S300,确定当前需要同步的增量数据。Step S300: Determine the incremental data that currently needs to be synchronized.
具体地,由于在对增量数据进行同步时,是定时执行的,因此,在进行数据同步之前,需要确定本次同步周期中所记录的增量数据,本次同步周期所记录的增量数据为在上一个同步周期的时间戳到本次同步周期的时间戳之间所记录的增量数据。比如,上一个同步周期的时间戳为15时12分10秒,本次同步周期的时间戳为15时13分10秒,则在15时12分10秒以及15时13分10秒这之间的时间段所记录的增量数据即为当前需要同步的增量数据。Specifically, because the incremental data is synchronized at regular intervals, it is necessary to determine the incremental data recorded in this synchronization cycle before the data synchronization is performed, and the incremental data recorded in this synchronization cycle It is the incremental data recorded between the time stamp of the last synchronization cycle and the time stamp of this synchronization cycle. For example, the time stamp of the last synchronization cycle is 15:12:10, and the time stamp of this synchronization cycle is 15:13:10, it is between 15:12:10 and 15:13:10 The incremental data recorded in the time period is the incremental data that needs to be synchronized currently.
步骤S302,获取每个增量数据所关联的第一数据表。Step S302: Obtain the first data table associated with each incremental data.
具体地,每个增量数据中都关联有一个第一数据表,不同的增量数据关联的第一数据表可能相同,也可能不同。Specifically, each incremental data is associated with a first data table, and the first data table associated with different incremental data may be the same or different.
步骤S304,根据所述第一数据表确定所述每个增量数据对应的目标数据库的地址信息。Step S304: Determine the address information of the target database corresponding to each incremental data according to the first data table.
具体地,在同步系统中预存有各个第一数据表与目标数据库的映射表,该映射表中包括各个第一数据表与目标数据库的对应关系,以及各个目标数据库的地址信息,所述地址信息包括所述目标服务器的IP地址、端口号等。在本实施例中,每个第一数据表可以和一个目标数据库相对应,也可以与多个目标数据库相对应。例如,数据表a与目标数据库B相对应,数据表b与目标数据库C与目标数据库D相对应等。Specifically, a mapping table between each first data table and the target database is pre-stored in the synchronization system, and the mapping table includes the corresponding relationship between each first data table and the target database, and the address information of each target database. The address information Including the IP address and port number of the target server. In this embodiment, each first data table may correspond to one target database, or may correspond to multiple target databases. For example, data table a corresponds to target database B, data table b corresponds to target database C and target database D, and so on.
步骤S306,根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中。Step S306: Synchronize each incremental data to the corresponding target database according to the address information.
具体地,同步系统在获取到该地址信息后,即可通过该目标服务器的地址将增量数据同步至对应的所述目标数据库中。Specifically, after obtaining the address information, the synchronization system can synchronize the incremental data to the corresponding target database through the address of the target server.
进一步地,在一实施方式中,所述根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中的步骤之后,还包括:Further, in an embodiment, after the step of synchronizing each incremental data to the corresponding target database according to the address information, the method further includes:
接收对应的所述目标数据库返回的数据同步结果;及Receiving the data synchronization result returned by the corresponding target database; and
若所述数据同步结果为同步成功,则对已同步的增量数据设置对应的标识。If the data synchronization result is that the synchronization is successful, a corresponding flag is set for the synchronized incremental data.
具体地,目标数据库在接收到增量数据之后,执行该增量数据中的SQL语句,从而实现数据的同步。目标数据库在执行数据同步操作之后,会给同步系统反馈一个数据同步结果,同步系统在接收到该同步结果之后,对该同步结果进行解析,进而可以根据解析后的同步结果确定目标数据库在对数据进行同步时是否成功的完成数据的同步,在确定该数据同步结果为同步成功时,可以对已完成同步的增量数据设置标识信息,比如设置“完成”标识,或者设置“1”标识,以表明该增量数据已完成数据的同步。在本实施例中,通过设置对应的标识,从而可以避免对同一个曾量数据进行多次重复的同步操作。Specifically, after receiving the incremental data, the target database executes the SQL statement in the incremental data, thereby achieving data synchronization. After the target database performs the data synchronization operation, it will feed back a data synchronization result to the synchronization system. After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine that the target database is checking the data according to the parsed synchronization result Whether the data synchronization was successfully completed during synchronization. When it is determined that the data synchronization result is a successful synchronization, you can set identification information for the incremental data that has been synchronized, such as setting the “complete” flag or the “1” flag to Indicates that the incremental data has completed data synchronization. In this embodiment, by setting the corresponding identifier, it is possible to avoid multiple repeated synchronization operations on the same amount of data.
在本申请另一实施方式中,当目标数据库在接收到增量数据之后,连续执行该增量数据中的SQL语句若干次(比如3次)后,仍未实现数据的同步,则可以反馈同步失败的同步结果给同步系统,同步系统在接收到该同步结果之后,对该同步结果进行解析,进而可以根据解析后的同步结果确定目标数据库在对数据进行同步时是否成功的完成数据的同步,在确定该数据同步结果为同步失败时,发送通知消息至预设用户。该通知消息可以通过邮件的方式发送,也可以通过短信的方式发送等。该预设用户优选为目标服务器的维护人员。In another embodiment of the present application, after the target database receives the incremental data, it continuously executes the SQL statement in the incremental data several times (for example, 3 times), and the data synchronization is still not achieved, then the synchronization can be fed back The failed synchronization result is sent to the synchronization system. After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine whether the target database successfully completes the data synchronization when synchronizing the data according to the parsed synchronization result. When it is determined that the data synchronization result is a synchronization failure, a notification message is sent to the preset user. The notification message can be sent by email or by SMS. The preset user is preferably a maintenance person of the target server.
进一步地,在另一实施方式中,在对增量数据成功完成数据同步时,可以将同步的增量数据存储至历史数据表中,以作为记录。在本实施例中,通过将同步成功的增量数据存储至历史数据表中,可以方便后续出现问题时,根据该历史数据表中的数据对问题进行排查。Further, in another embodiment, when the data synchronization of the incremental data is successfully completed, the synchronized incremental data may be stored in the historical data table as a record. In this embodiment, by storing the successfully synchronized incremental data in the historical data table, it is convenient to troubleshoot the problem based on the data in the historical data table when a problem occurs later.
参阅图4,是本申请数据库间数据同步方法第二实施例的实施流程示意图。在本实施例中,根据不同的需求,图4所示的流程图中的步骤的执行顺序可以改变,某些步骤可以省略。下面以数据库间数据同步系统(下文以“同步系统”简称)为执行主体进行示例性描述,所述同步系统可以应用于服务器中。具体如下:Refer to FIG. 4, which is a schematic diagram of the implementation process of the second embodiment of the data synchronization method between databases of the present application. In this embodiment, according to different requirements, the execution order of the steps in the flowchart shown in FIG. 4 can be changed, and some steps can be omitted. The following exemplarily describes an inter-database data synchronization system (hereinafter referred to as “synchronization system” for short) as the execution subject, and the synchronization system can be applied to a server. details as follows:
步骤S400,设置与所述数据处理业务对应的数据记录范围,并将所述数据记录范围添加至所述同步记录表中。Step S400: Set a data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
具体地,可以根据业务需求设置数据处理业务对应的数据记录范围,所述数据记录范围为具体需对该源数据库中的哪些数据表进行同步。该数据记录范围可以预先设定,也可以在后期根据用户的输入信息进行设定。例如,若用户需要对源数据库中的数据表a进行同步,则用户可以将所述数据表a对应的信息输入至同步系统,同步系统在接收到该输入信息后,根据该输入信息设置所述数据记录范围。Specifically, the data record range corresponding to the data processing service can be set according to business requirements, and the data record range is specifically which data tables in the source database need to be synchronized. The data recording range can be set in advance, or can be set later based on user input information. For example, if the user needs to synchronize the data table a in the source database, the user can input the information corresponding to the data table a to the synchronization system. After receiving the input information, the synchronization system sets the data table a according to the input information. Data logging range.
在设置好该数据记录范围之后,将即该数据记录范围添加至同步记录表中。After setting the data record range, add the data record range to the synchronization record table.
步骤S402,获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令。Step S402: Obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction. The data operation instruction is an instruction based on a SQL statement.
步骤S404,判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Step S404: Determine whether there is a data table matching the table name in the preset synchronization record table;
步骤S406,若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据。Step S406, if it exists, record the incremental data generated by the data processing service executed according to the data operation instruction.
步骤S408,定时将所述增量数据同步至目标数据库。Step S408: Synchronize the incremental data to the target database regularly.
上述步骤S402-S408与步骤S100-S106类似,在本实施方式中不再赘述。The foregoing steps S402-S408 are similar to steps S100-S106, and will not be repeated in this embodiment.
本申请实施例所提出的数据库间数据同步方法,通过设置与所述数据处理业务对应的数据记录范围,从而使得系统具有很好的扩展性。In the method for data synchronization between databases proposed in the embodiments of the present application, by setting the data record range corresponding to the data processing service, the system has good scalability.
请参阅图5,示出了本申请实施例之数据库间数据同步系统500(以下简称为“同步系统”500)的程序模块示意图。在本实施例中,同步系统500可以包括或被分割成一个或多个程序模块,一个或者多个程序模块被存储于存储介质中,并由一个或多个处理器所执行,以完成本申请,并可实现上述数据库间数据同步方法。本申请实施例所称的程序模块是指能够完成特定功能的一系列计算机可读指令的指令段,比程序本身更适合于描述数据库间数据同步方法在存储介质中的执行过程。以下描述将具体介绍本实施例各程序模块的功能:Please refer to FIG. 5, which shows a schematic diagram of program modules of an inter-database data synchronization system 500 (hereinafter referred to as "synchronization system" 500) according to an embodiment of the present application. In this embodiment, the synchronization system 500 may include or be divided into one or more program modules, and the one or more program modules are stored in a storage medium and executed by one or more processors to complete the application , And can realize the above-mentioned data synchronization method between databases. The program module referred to in the embodiments of the present application refers to an instruction segment of a series of computer-readable instructions capable of completing specific functions, and is more suitable for describing the execution process of the data synchronization method between databases in the storage medium than the program itself. The following description will specifically introduce the functions of each program module in this embodiment:
获取模块501,用于获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令。The obtaining module 501 is configured to obtain a data operation instruction, and parse the data operation instruction to obtain a table name of a data table included in the data operation instruction, and the data operation instruction is an instruction based on a SQL statement.
具体地,获取模块501可以获取用户设备发送的数据操作指令,所述数据操作指令可以包括数据新增指令、数据删除指令、数据修改指令等等。获取模块501在接收到数据操作指令之后,可进一步根据所述数据操作指令执行数据处理业务,所述数据处理业务可以包括对数据库进行数据新增业务、数据删除业务、数据修改业务等。例如,若所述数据操作指令为数据修改指令,则所述获取模块501根据所述数据修改指令对数据库中的相应是数据进行修改。Specifically, the obtaining module 501 may obtain a data operation instruction sent by a user equipment, and the data operation instruction may include a data addition instruction, a data deletion instruction, a data modification instruction, and so on. After receiving the data operation instruction, the acquisition module 501 may further execute data processing services according to the data operation instructions. The data processing services may include data addition services, data deletion services, data modification services, etc., to the database. For example, if the data operation instruction is a data modification instruction, the acquisition module 501 modifies the corresponding data in the database according to the data modification instruction.
在本实施例中,获取模块501在接收到数据操作指令之后,也可以对数据操作指令进行解析,从而得到该数据操作指令中所涉及的数据表信息,所述数据表信息包括数据表的表名。In this embodiment, after receiving the data operation instruction, the acquisition module 501 can also parse the data operation instruction to obtain the data table information involved in the data operation instruction. The data table information includes the table of the data table. name.
需要说明的是,本申请实施例中的数据操作指令是基于SQL(Structured Query Language,结构化查询语言)语句的指令,即所述数据操作指令是一条SQL语句。It should be noted that the data operation instruction in the embodiment of the present application is an instruction based on a SQL (Structured Query Language) statement, that is, the data operation instruction is an SQL statement.
进一步地,在一实施例中,所述获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名的步骤包括:通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及用于对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。Further, in one embodiment, the step of obtaining the data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction includes: checking all the data through the mybtis interceptor. The data operation instruction is intercepted, and the SQL statement in the data operation instruction is obtained; and used to parse the SQL statement to extract the table name of the data table contained in the SQL statement.
具体地,获取模块501可以调用mybtis拦截器对数据操作指令进行拦截,从而捕获数据操作指令中的SQL语句,在捕获到SQL语句后,可以进一步对该SQL语句进行解析,从而提取出该SQL语句中所的数据表信息,该数据表信息中包含有数据表的表名。Specifically, the acquisition module 501 can call the mybtis interceptor to intercept the data operation instruction, thereby capturing the SQL statement in the data operation instruction. After the SQL statement is captured, the SQL statement can be further parsed to extract the SQL statement The data table information in the data table information contains the table name of the data table.
在发明实施中,当不需要获取数据操作指令中包含的数据表的表名时,可以将该mybtis拦截器进行屏蔽。In the implementation of the invention, when the table name of the data table contained in the data operation instruction does not need to be obtained, the mybtis interceptor can be shielded.
判断模块502,用于判断预设的同步记录表中是否存在与所述表名相匹配的数据表。The judging module 502 is configured to judge whether there is a data table matching the table name in the preset synchronization record table.
具体地,所述同步记录表为源数据库的各个数据表中需要同步的数据表。该同步记录表可以根据业务需求进行设定,例如,当前业务需求为需要对源数据库中的数据表A与数据表B中被修改的数据进行同步,则可以设定所述同步记录表中包括数据表A与数据表B,即后续只需要对数据表A与数据表B中被修改的数据进行同步,对于其他数据表中的数据不需要同步;若当前业务需求为需要对源数据库进行同步,则可以设定所述同步记录表中包括源数据库中的所有数据表,即后续只要源数据库中的数据被修改,都要对修改的数据进行同步。Specifically, the synchronization record table is a data table that needs to be synchronized in each data table of the source database. The synchronization record table can be set according to business requirements. For example, if the current business requirement is to synchronize the modified data in data table A and data table B in the source database, the synchronization record table can be set to include Data table A and data table B, that is, only the modified data in data table A and data table B need to be synchronized in the future, and the data in other data tables does not need to be synchronized; if the current business requirement is to synchronize the source database , You can set the synchronization record table to include all data tables in the source database, that is, as long as the data in the source database is modified subsequently, the modified data must be synchronized.
在具体地判断过程中,可以将获得到的表名与同步记录表中所包含的各个数据表的表名一一与该获得到的表名进行比较,以确定该同步记录表中是否存在与所述表名相匹配的数据表。In the specific judgment process, the obtained table name and the table name of each data table contained in the synchronization record table can be compared with the obtained table name one by one to determine whether the synchronization record table exists and The data table whose table name matches.
记录模块503,用于当存在与所述表名相匹配的数据表时,记录根据所述数据操作指令执行的数据处理业务所生成的增量数据。The recording module 503 is configured to record the incremental data generated by the data processing service executed according to the data operation instruction when there is a data table matching the table name.
具体地,当存在与所述表名相匹配的数据表时,表明需要对该数据操作指令所执行的数据处理业务进行同步。因而,在当存在与所述表名相匹配的数据表时,记录模块503需要记录根据所述数据操作指令执行的数据处理业务所生成的增量数据。所述增量数据包括所述数据操作指令所对应的SQL语句以及该SQL语句所涉及到的数据表信息、数据库信息等。Specifically, when there is a data table matching the table name, it indicates that the data processing service executed by the data operation instruction needs to be synchronized. Therefore, when there is a data table matching the table name, the recording module 503 needs to record the incremental data generated by the data processing service executed according to the data operation instruction. The incremental data includes the SQL statement corresponding to the data operation instruction and the data table information, database information, etc. involved in the SQL statement.
同步模块504,用于定时将所述增量数据同步至目标数据库。The synchronization module 504 is configured to periodically synchronize the incremental data to the target database.
具体地,同步模块504定时会将增量数据同步至目标数据库,比如,每隔1分钟将所有的增量数据同步至目标数据库中。所述目标数据库为要将源数据库中的数据同步至其中的数据库,该目标数据库可以有多个,比如,数据库A、数据库B,数据库C等。Specifically, the synchronization module 504 periodically synchronizes the incremental data to the target database, for example, synchronizes all the incremental data to the target database every 1 minute. The target database is the database to which the data in the source database is to be synchronized, and there may be multiple target databases, for example, database A, database B, database C, etc.
在本实施例中,在对增量数据进行同步时,可以在目标数据库中执行该增量数据中所包含的SQL语句,从而实现数据的同步。In this embodiment, when the incremental data is synchronized, the SQL statement contained in the incremental data can be executed in the target database, thereby achieving data synchronization.
可以理解的是,为了将源数据中的增量数据同步至目标数据库中,需要预先将目标数据库的地址维护到源数据库中。It is understandable that in order to synchronize the incremental data in the source data to the target database, the address of the target database needs to be maintained in the source database in advance.
本申请本实施例所提出的数据库间数据同步系统,通过获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;判断预设的同步记录表中是否存在与所述表名相匹配的数据表;若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及定时将所述增量数据同步至目标数据库,从而能够增加系统的可扩展性,降低开发成本。The data synchronization system between databases proposed in this embodiment of the application obtains the data operation instruction and parses the data operation instruction to obtain the table name of the data table included in the data operation instruction. It is an instruction based on SQL statement; it is determined whether there is a data table matching the table name in the preset synchronization record table; if it exists, it records the incremental data generated by the data processing service executed according to the data operation instruction ; And regularly synchronize the incremental data to the target database, which can increase the scalability of the system and reduce development costs.
进一步地,在一实施方式中,所述定时将所述增量数据同步至目标数据库的步骤包括:Further, in an embodiment, the step of periodically synchronizing the incremental data to the target database includes:
步骤1,确定当前需要同步的增量数据。Step 1. Determine the incremental data that currently needs to be synchronized.
具体地,由于在对增量数据进行同步时,是定时执行的,因此,在进行数据同步之前,需要确定本次同步周期中所记录的增量数据,本次同步周期所记录的增量数据为在上一个同步周期的时间戳到本次同步周期的时间戳之间所记录的增量数据。比如,上一个同步周期的时间戳为15时12分10秒,本次同步周期的时间戳为15时13分10秒,则在15时12分10秒以及15时13分10秒这之间的时间段所记录的增量数据即为当前需要同步的增量数据。Specifically, because the incremental data is synchronized at regular intervals, it is necessary to determine the incremental data recorded in this synchronization cycle before the data synchronization is performed, and the incremental data recorded in this synchronization cycle It is the incremental data recorded between the time stamp of the last synchronization cycle and the time stamp of this synchronization cycle. For example, the time stamp of the last synchronization cycle is 15:12:10, and the time stamp of this synchronization cycle is 15:13:10, it is between 15:12:10 and 15:13:10 The incremental data recorded in the time period is the incremental data that needs to be synchronized currently.
步骤2,获取每个增量数据所关联的第一数据表。Step 2: Obtain the first data table associated with each incremental data.
具体地,每个增量数据中都关联有一个第一数据表,不同的增量数据关联的第一数据表可能相同,也可能不同。Specifically, each incremental data is associated with a first data table, and the first data table associated with different incremental data may be the same or different.
步骤3,根据所述第一数据表确定所述每个增量数据对应的目标数据库的地址信息。Step 3: Determine the address information of the target database corresponding to each incremental data according to the first data table.
具体地,在同步系统中预存有各个第一数据表与目标数据库的映射表,该映射表中包括各个第一数据表与目标数据库的对应关系,以及各个目标数据库的地址信息,所述地址信息包括所述目标服务器的IP地址、端口号等。在本实施例中,每个第一数据表可以和一个目标数据库相对应,也可以与多个目标数据库相对应。例如,数据表a与目标数据库B相对应,数据表b与目标数据库C与目标数据库D相对应等。Specifically, a mapping table between each first data table and the target database is pre-stored in the synchronization system, and the mapping table includes the corresponding relationship between each first data table and the target database, and the address information of each target database. The address information Including the IP address and port number of the target server. In this embodiment, each first data table may correspond to one target database, or may correspond to multiple target databases. For example, data table a corresponds to target database B, data table b corresponds to target database C and target database D, and so on.
步骤4,根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中。Step 4. Synchronize each incremental data to the corresponding target database according to the address information.
具体地,同步系统在获取到该地址信息后,即可通过该目标服务器的地址将增量数据同步至对应的所述目标数据库中。Specifically, after obtaining the address information, the synchronization system can synchronize the incremental data to the corresponding target database through the address of the target server.
进一步地,在一实施方式中,所述根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中的步骤之后,还包括:Further, in an embodiment, after the step of synchronizing each incremental data to the corresponding target database according to the address information, the method further includes:
接收对应的所述目标数据库返回的数据同步结果;及Receiving the data synchronization result returned by the corresponding target database; and
若所述数据同步结果为同步成功,则对已同步的增量数据设置对应的标识。If the data synchronization result is that the synchronization is successful, a corresponding flag is set for the synchronized incremental data.
具体地,目标数据库在接收到增量数据之后,执行该增量数据中的SQL语句,从而实现数据的同步。目标数据库在执行数据同步操作之后,会给同步系统反馈一个数据同步结果,同步系统在接收到该同步结果之后,对该同步结果进行解析,进而可以根据解析后的同步结果确定目标数据库在对数据进行同步时是否成功的完成数据的同步,在确定该数据同步结果为同步成功时,可以对已完成同步的增量数据设置标识信息,比如设置“完成”标识,或者设置“1”标识,以表明该增量数据已完成数据的同步。在本实施例中,通过设置对应的标识,从而可以避免对同一个曾量数据进行多次重复的同步操作。Specifically, after receiving the incremental data, the target database executes the SQL statement in the incremental data, thereby achieving data synchronization. After the target database performs the data synchronization operation, it will feed back a data synchronization result to the synchronization system. After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine that the target database is checking the data according to the parsed synchronization result Whether the data synchronization was successfully completed during synchronization. When it is determined that the data synchronization result is a successful synchronization, you can set identification information for the incremental data that has been synchronized, such as setting the “complete” flag or the “1” flag to Indicates that the incremental data has completed data synchronization. In this embodiment, by setting the corresponding identifier, it is possible to avoid multiple repeated synchronization operations on the same amount of data.
在本申请另一实施方式中,当目标数据库在接收到增量数据之后,连续执行该增量数据中的SQL语句若干次(比如3次)后,仍未实现数据的同步,则可以反馈同步失败的同步结果给同步系统,同步系统在接收到该同步结果之后,对该同步结果进行解析,进而可以根据解析后的同步结果确定目标数据库在对数据进行同步时是否成功的完成数据的同步,在确定该数据同步结果为同步失败时,发送通知消息至预设用户。该通知消息可以通过邮件的方式发送,也可以通过短信的方式发送等。该预设用户优选为目标服务器的维护人员。In another embodiment of the present application, after the target database receives the incremental data, it continuously executes the SQL statement in the incremental data several times (for example, 3 times), and the data synchronization is still not achieved, then the synchronization can be fed back The failed synchronization result is sent to the synchronization system. After receiving the synchronization result, the synchronization system parses the synchronization result, and then can determine whether the target database successfully completes the data synchronization when synchronizing the data according to the parsed synchronization result. When it is determined that the data synchronization result is a synchronization failure, a notification message is sent to the preset user. The notification message can be sent by email or by SMS. The preset user is preferably a maintenance person of the target server.
进一步地,在另一实施方式中,在对增量数据成功完成数据同步时,可以将同步的增量数据存储至历史数据表中,以作为记录。在本实施例中,通过将同步成功的增量数据存储至历史数据表中,可以方便后续出现问题时,根据该历史数据表中的数据对问题进行排查。Further, in another embodiment, when the data synchronization of the incremental data is successfully completed, the synchronized incremental data may be stored in the historical data table as a record. In this embodiment, by storing the successfully synchronized incremental data in the historical data table, it is convenient to troubleshoot the problem based on the data in the historical data table when a problem occurs later.
在本申请另一实施方式中,所述同步系统500还包括:In another embodiment of the present application, the synchronization system 500 further includes:
设置模块,用于设置与所述数据处理业务对应的数据记录范围,并将所述数据记录范围添加至所述同步记录表中。The setting module is used to set the data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
具体地,可以根据业务需求设置数据处理业务对应的数据记录范围,所述数据记录范围为具体需对该源数据库中的哪些数据表进行同步。该数据记录范围可以预先设定,也可以在后期根据用户的输入信息进行设定。例如,若用户需要对源数据库中的数据表a进行同步,则用户可以将所述数据表a对应的信息输入至同步系统的设置模块,设置模块在接收到该输入信息后,根据该输入信息设置所述数据记录范围。Specifically, the data record range corresponding to the data processing service can be set according to business requirements, and the data record range is specifically which data tables in the source database need to be synchronized. The data recording range can be set in advance, or can be set later based on user input information. For example, if the user needs to synchronize the data table a in the source database, the user can input the information corresponding to the data table a into the setting module of the synchronization system. After receiving the input information, the setting module will use the input information Set the data recording range.
在设置好该数据记录范围之后,将即该数据记录范围添加至同步记录表中。After setting the data record range, add the data record range to the synchronization record table.
参阅图6,是本申请实施例之计算机设备600的硬件架构示意图。在本实施例中,所述计算机设备600是一种能够按照事先设定或者存储的指令,自动进行数值计算和/或信息处理的设备。如图所示,所述计算机设备600至少包括,但不限于,可通过系统总线相互通信连接存储器601、处理器602、网络接口603、以及数据库间数据同步系统604。其中:Refer to FIG. 6, which is a schematic diagram of the hardware architecture of a computer device 600 according to an embodiment of the present application. In this embodiment, the computer device 600 is a device that can automatically perform numerical calculation and/or information processing according to pre-set or stored instructions. As shown in the figure, the computer device 600 at least includes, but is not limited to, a memory 601, a processor 602, a network interface 603, and a data synchronization system 604 between databases that can communicate with each other through a system bus. among them:
本实施例中,存储器601至少包括一种类型的非易失性计算机可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,存储器601可以是计算机设备600的内部存储单元,例如该计算机设备600的硬盘或内存。在另一些实施例中,存储器601也可以是计算机设备600的外部存储设备,例如该计算机设备600上配备的插接式硬盘,智能存储卡(Smart Media Card, SMC),安全数字(Secure Digital, SD)卡,闪存卡(Flash Card)等。当然,存储器601还可以既包括计算机设备600的内部存储单元也包括其外部存储设备。本实施例中,存储器601通常用于存储安装于计算机设备600的操作系统和各类应用软件,例如数据库间数据同步系统604的程序代码等。此外,存储器601还可以用于暂时地存储已经输出或者将要输出的各类数据。In this embodiment, the memory 601 includes at least one type of non-volatile computer-readable storage medium. The readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), Random access memory (RAM), static random access memory (SRAM), read only memory (ROM), electrically erasable programmable read only memory (EEPROM), programmable read only memory (PROM), magnetic memory, magnetic disk, optical disk Wait. In some embodiments, the memory 601 may be an internal storage unit of the computer device 600, such as a hard disk or memory of the computer device 600. In other embodiments, the memory 601 may also be an external storage device of the computer device 600, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), and a secure digital (Secure Digital, SD) card, flash card (Flash Card), etc. Of course, the memory 601 may also include both the internal storage unit of the computer device 600 and its external storage device. In this embodiment, the memory 601 is generally used to store the operating system and various application software installed in the computer device 600, such as the program code of the data synchronization system 604 between databases. In addition, the memory 601 can also be used to temporarily store various types of data that have been output or will be output.
处理器602在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器602通常用于控制计算机设备600的总体操作。本实施例中,处理器602用于运行存储器601中存储的程序代码或者处理数据,例如运行数据库间数据同步系统604,以实现上述各个实施例中的数据库间数据同步方法。The processor 602 may be a central processing unit (Central Processing Unit, CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments. The processor 602 is generally used to control the overall operation of the computer device 600. In this embodiment, the processor 602 is configured to run the program code or process data stored in the memory 601, for example, to run the inter-database data synchronization system 604 to implement the inter-database data synchronization method in each of the foregoing embodiments.
所述网络接口603可包括无线网络接口或有线网络接口,该网络接口603通常用于在所述计算机设备600与其他电子装置之间建立通信连接。例如,所述网络接口603用于通过网络将所述计算机设备600与外部终端相连,在所述计算机设备600与外部终端之间的建立数据传输通道和通信连接等。所述网络可以是企业内部网(Intranet)、互联网(Internet)、全球移动通讯系统(Global System of Mobile communication,GSM)、宽带码分多址(Wideband Code Division Multiple Access,WCDMA)、4G网络、5G网络、蓝牙(Bluetooth)、Wi-Fi等无线或有线网络。The network interface 603 may include a wireless network interface or a wired network interface, and the network interface 603 is generally used to establish a communication connection between the computer device 600 and other electronic devices. For example, the network interface 603 is used to connect the computer device 600 to an external terminal through a network, and to establish a data transmission channel and a communication connection between the computer device 600 and the external terminal. The network may be an intranet (Intranet), the Internet (Internet), a global system of mobile communications (Global System of Mobile) communication, GSM), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), 4G network, 5G network, Bluetooth (Bluetooth), Wi-Fi and other wireless or wired networks.
需要指出的是,图6仅示出了具有部件601-604的计算机设备600,但是应理解的是,并不要求实施所有示出的部件,可以替代的实施更多或者更少的部件。It should be pointed out that FIG. 6 only shows a computer device 600 with components 601-604, but it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead.
在本实施例中,存储于存储器601中的所述数据库间数据同步系统604还可以被分割为一个或者多个程序模块,所述一个或者多个程序模块被存储于存储器601中,并由一个或多个处理器(本实施例为处理器602)所执行,以完成本申请之数据库间数据同步方法。In this embodiment, the inter-database data synchronization system 604 stored in the memory 601 can also be divided into one or more program modules, and the one or more program modules are stored in the memory 601 and consist of one Or executed by multiple processors (processor 602 in this embodiment) to complete the data synchronization method between databases of this application.
本实施例还提供一种非易失性计算机可读存储介质,如闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘、服务器、App应用商城等等,其上存储有计算机可读指令,程序被处理器执行时实现相应功能。本实施例的非易失性计算机可读存储介质用于存储数据库间数据同步系统500或604,以被处理器执行时实现如下步骤:This embodiment also provides a non-volatile computer-readable storage medium, such as flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory ( SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, server, App application mall, etc., on which storage There are computer-readable instructions, and the corresponding functions are realized when the program is executed by the processor. The non-volatile computer-readable storage medium of this embodiment is used to store the inter-database data synchronization system 500 or 604, so as to implement the following steps when executed by a processor:
获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;Acquiring a data operation instruction, and analyzing the data operation instruction to obtain a table name of a data table included in the data operation instruction, where the data operation instruction is an instruction based on a SQL statement;
判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Judging whether there is a data table matching the table name in the preset synchronization record table;
若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及If it exists, record the incremental data generated by the data processing service executed according to the data operation instruction; and
定时将所述增量数据同步至目标数据库。Synchronize the incremental data to the target database regularly.
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。The serial numbers of the foregoing embodiments of the present application are only for description, and do not represent the advantages and disadvantages of the embodiments.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。Through the description of the above embodiments, those skilled in the art can clearly understand that the method of the above embodiments can be implemented by means of software plus the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better.的实施方式。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本申请的专利保护范围内。The above are only preferred embodiments of this application, and do not limit the scope of this application. Any equivalent structure or equivalent process transformation made using the content of the description and drawings of this application, or directly or indirectly used in other related technical fields , The same reason is included in the scope of patent protection of this application.

Claims (20)

  1. 一种数据库间数据同步方法,包括以下步骤:A method for data synchronization between databases includes the following steps:
    获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;Acquiring a data operation instruction, and analyzing the data operation instruction to obtain a table name of a data table included in the data operation instruction, where the data operation instruction is an instruction based on a SQL statement;
    判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Judging whether there is a data table matching the table name in the preset synchronization record table;
    若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及If it exists, record the incremental data generated by the data processing service executed according to the data operation instruction; and
    定时将所述增量数据同步至目标数据库。Synchronize the incremental data to the target database regularly.
  2. 如权利要求1所述的数据库间数据同步方法,所述数据库间数据同步方法还包括:The method for data synchronization between databases according to claim 1, wherein the method for data synchronization between databases further comprises:
    设置与所述数据处理业务对应的数据记录范围,并将所述数据记录范围添加至所述同步记录表中。Set a data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
  3. 如权利要求 1所述的数据库间数据同步方法,所述获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名的步骤包括:The method for data synchronization between databases according to claim 1, wherein the step of obtaining a data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction comprises:
    通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及Intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction; and
    对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。The SQL statement is parsed to extract the table name of the data table contained in the SQL statement.
  4. 如权利要求 2所述的数据库间数据同步方法,所述获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名的步骤包括:3. The method for data synchronization between databases according to claim 2, wherein the step of obtaining a data operation instruction and analyzing the data operation instruction to obtain the table name of the data table included in the data operation instruction comprises:
    通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及Intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction; and
    对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。The SQL statement is parsed to extract the table name of the data table contained in the SQL statement.
  5. 如权利要求1所述的数据库间数据同步方法,所述定时将所述增量数据同步至目标数据库的步骤包括:8. The method for data synchronization between databases according to claim 1, wherein the step of regularly synchronizing the incremental data to the target database comprises:
    确定当前需要同步的增量数据;Determine the incremental data that currently needs to be synchronized;
    获取每个增量数据所关联的第一数据表;Acquiring the first data table associated with each incremental data;
    根据所述第一数据表确定所述每个增量数据对应的目标数据库的地址信息;及Determining the address information of the target database corresponding to each incremental data according to the first data table; and
    根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中。Synchronize each incremental data to the corresponding target database according to the address information.
  6. 如权利要求2所述的数据库间数据同步方法,所述定时将所述增量数据同步至目标数据库的步骤包括:3. The method for data synchronization between databases according to claim 2, wherein the step of regularly synchronizing the incremental data to the target database comprises:
    确定当前需要同步的增量数据;Determine the incremental data that currently needs to be synchronized;
    获取每个增量数据所关联的第一数据表;Acquiring the first data table associated with each incremental data;
    根据所述第一数据表确定所述每个增量数据对应的目标数据库的地址信息;及Determining the address information of the target database corresponding to each incremental data according to the first data table; and
    根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中。Synchronize each incremental data to the corresponding target database according to the address information.
  7. 如权利要求5所述的数据库间数据同步方法,所述根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中的步骤之后,还包括:8. The method for data synchronization between databases according to claim 5, after the step of synchronizing each incremental data to the corresponding target database according to the address information, the method further comprises:
    接收对应的所述目标数据库返回的数据同步结果;及Receiving the data synchronization result returned by the corresponding target database; and
    若所述数据同步结果为同步成功,则对已同步的增量数据设置对应的标识。If the data synchronization result is that the synchronization is successful, a corresponding flag is set for the synchronized incremental data.
  8. 如权利要求6所述的数据库间数据同步方法,所述根据所述地址信息将所述每个增量数据同步至对应的所述目标数据库中的步骤之后,还包括:7. The method for data synchronization between databases according to claim 6, after the step of synchronizing each incremental data to the corresponding target database according to the address information, further comprising:
    接收对应的所述目标数据库返回的数据同步结果;及Receiving the data synchronization result returned by the corresponding target database; and
    若所述数据同步结果为同步成功,则对已同步的增量数据设置对应的标识。If the data synchronization result is that the synchronization is successful, a corresponding flag is set for the synchronized incremental data.
  9. 如权利要求7所述的数据库间数据同步方法,所述接收对应的所述目标数据库返回的数据同步结果的步骤之后,还包括:8. The method for data synchronization between databases according to claim 7, after the step of receiving the data synchronization result returned by the corresponding target database, further comprising:
    若所述数据同步结果为同步失败,则发送通知消息至预设用户。If the result of the data synchronization is that the synchronization fails, a notification message is sent to the preset user.
  10. 如权利要求8所述的数据库间数据同步方法,所述接收对应的所述目标数据库返回的数据同步结果的步骤之后,还包括:8. The method for data synchronization between databases according to claim 8, after the step of receiving the data synchronization result returned by the corresponding target database, further comprising:
    若所述数据同步结果为同步失败,则发送通知消息至预设用户。If the result of the data synchronization is that the synchronization fails, a notification message is sent to the preset user.
  11. 如权利要求7所述的数据库间数据同步方法,所述数据库间数据同步方法还包括:8. The method for data synchronization between databases according to claim 7, wherein the method for data synchronization between databases further comprises:
    将已同步的增量数据存储至历史数据表中。Store the synchronized incremental data in the historical data table.
  12. 如权利要求8所述的数据库间数据同步方法,所述数据库间数据同步方法还包括:8. The method for data synchronization between databases according to claim 8, wherein the method for data synchronization between databases further comprises:
    将已同步的增量数据存储至历史数据表中。Store the synchronized incremental data in the historical data table.
  13. 一种数据库间数据同步系统,包括:A data synchronization system between databases, including:
    获取模块,用于获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;The acquisition module is used to acquire a data operation instruction, and parse the data operation instruction to obtain the table name of the data table contained in the data operation instruction, and the data operation instruction is an instruction based on a SQL statement;
    判断模块,用于判断预设的同步记录表中是否存在与所述表名相匹配的数据表;The judgment module is used to judge whether there is a data table matching the table name in the preset synchronization record table;
    记录模块,用于若存在与所述表名相匹配的数据表,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及The recording module is used to record the incremental data generated by the data processing service executed according to the data operation instruction if there is a data table matching the table name; and
    同步模块,用于定时将所述增量数据同步至目标数据库。The synchronization module is used to periodically synchronize the incremental data to the target database.
  14. 如权利要求13所述的数据库间数据同步系统,所述数据库间数据同步系统还包括:The data synchronization system between databases according to claim 13, wherein the data synchronization system between databases further comprises:
    设置模块,用于设置与所述数据处理业务对应的数据记录范围,并将所述数据记录范围添加至所述同步记录表中。The setting module is used to set the data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
  15. 如权利要求13所述的数据库间数据同步系统,所述获取模块,还用于通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及用于对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。The data synchronization system between databases according to claim 13, wherein the acquisition module is also used to intercept the data operation instruction through the mybtis interceptor, and to acquire the SQL statement in the data operation instruction; and The SQL statement is parsed to extract the table name of the data table contained in the SQL statement.
  16. 如权利要求14所述的数据库间数据同步系统,所述获取模块,还用于通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及用于对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。The data synchronization system between databases according to claim 14, wherein the acquisition module is also used to intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction; and The SQL statement is parsed to extract the table name of the data table contained in the SQL statement.
  17. 一种计算机设备,包括存储器、处理器以及存储在所述存储器上并可在所述处理器上运行的计算机可读指令,所述处理器执行所述计算机可读指令时执行以下步骤:A computer device includes a memory, a processor, and computer readable instructions stored on the memory and running on the processor, and the processor executes the following steps when the processor executes the computer readable instructions:
    获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;Acquiring a data operation instruction, and analyzing the data operation instruction to obtain a table name of a data table included in the data operation instruction, where the data operation instruction is an instruction based on a SQL statement;
    判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Judging whether there is a data table matching the table name in the preset synchronization record table;
    若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及If it exists, record the incremental data generated by the data processing service executed according to the data operation instruction; and
    定时将所述增量数据同步至目标数据库。Synchronize the incremental data to the target database regularly.
  18. 如权利要求17所述的计算机设备,所述处理器执行所述计算机可读指令时还执行以下步骤:17. The computer device of claim 17, wherein the processor further executes the following steps when executing the computer-readable instructions:
    设置与所述数据处理业务对应的数据记录范围,并将所述数据记录范围添加至所述同步记录表中。Set a data record range corresponding to the data processing service, and add the data record range to the synchronization record table.
  19. 如权利要求17所述的计算机设备,所述处理器执行所述计算机可读指令时还执行以下步骤:17. The computer device of claim 17, wherein the processor further executes the following steps when executing the computer-readable instructions:
    通过mybtis拦截器对所述数据操作指令进行拦截,并获取所述数据操作指令中的SQL语句;及Intercept the data operation instruction through the mybtis interceptor, and obtain the SQL statement in the data operation instruction; and
    对所述SQL语句进行解析,以提取出所述SQL语句中所包含的数据表的表名。The SQL statement is parsed to extract the table name of the data table contained in the SQL statement.
  20. 一种非易失性计算机可读存储介质,所述非易失性计算机可读存储介质存储有计算机可读指令,所述计算机可读指令可被至少一个处理器执行,以使所述至少一个处理器执行以下步骤:A non-volatile computer-readable storage medium, the non-volatile computer-readable storage medium stores computer-readable instructions, the computer-readable instructions can be executed by at least one processor, so that the at least one The processor performs the following steps:
    获取数据操作指令,并对所述数据操作指令进行解析以得到所述数据操作指令中包含的数据表的表名,所述数据操作指令为基于SQL语句的指令;Acquiring a data operation instruction, and analyzing the data operation instruction to obtain a table name of a data table included in the data operation instruction, where the data operation instruction is an instruction based on a SQL statement;
    判断预设的同步记录表中是否存在与所述表名相匹配的数据表;Judging whether there is a data table matching the table name in the preset synchronization record table;
    若存在,则记录根据所述数据操作指令执行的数据处理业务所生成的增量数据;及If it exists, record the incremental data generated by the data processing service executed according to the data operation instruction; and
    定时将所述增量数据同步至目标数据库。Synchronize the incremental data to the target database regularly.
PCT/CN2019/102843 2019-06-14 2019-08-27 Method and system for synchronizing data between databases, computer device and storage medium WO2020248375A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910513290.2 2019-06-14
CN201910513290.2A CN110347747A (en) 2019-06-14 2019-06-14 Database data synchronic method, system, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2020248375A1 true WO2020248375A1 (en) 2020-12-17

Family

ID=68181979

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/102843 WO2020248375A1 (en) 2019-06-14 2019-08-27 Method and system for synchronizing data between databases, computer device and storage medium

Country Status (2)

Country Link
CN (1) CN110347747A (en)
WO (1) WO2020248375A1 (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111309742A (en) * 2020-01-20 2020-06-19 深圳壹账通智能科技有限公司 Data synchronization method and device, computer equipment and storage medium
CN111400397B (en) * 2020-02-29 2023-04-11 平安科技(深圳)有限公司 Data synchronization method, device, equipment and computer storage medium
CN111324614B (en) * 2020-03-18 2023-07-28 浩云科技股份有限公司 Table configuration method and device, terminal equipment and storage medium
CN112015738A (en) * 2020-08-28 2020-12-01 支付宝(杭州)信息技术有限公司 Method and device for realizing linked list processing of multiple data detail lists
CN112069194A (en) * 2020-08-31 2020-12-11 杭州铁驰云商科技有限公司 Real-time modification method and system for data in database
CN112612797B (en) * 2020-12-30 2022-08-23 杭州拼便宜网络科技有限公司 Multi-source same-table data loading method, device, equipment and medium
CN112559638B (en) * 2021-02-20 2021-05-07 恒生电子股份有限公司 Data synchronization method, device, equipment and storage medium
CN114238523A (en) * 2021-12-17 2022-03-25 蚂蚁区块链科技(上海)有限公司 Data synchronization method and device
CN115952172B (en) * 2023-03-08 2023-05-26 畅捷通信息技术股份有限公司 Data matching method and device based on database temporary table

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105912949A (en) * 2016-04-13 2016-08-31 北京京东尚科信息技术有限公司 Data permission management method, data permission management system and service management system
CN106294075A (en) * 2016-08-17 2017-01-04 浪潮软件股份有限公司 A kind of SQL is monitored method, Apparatus and system
CN108205560A (en) * 2016-12-19 2018-06-26 腾讯科技(深圳)有限公司 A kind of method of data synchronization and device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10545943B2 (en) * 2016-04-05 2020-01-28 International Business Machines Corporation Change stream analytics for data replication systems
CN108595522A (en) * 2018-03-27 2018-09-28 北京明朝万达科技股份有限公司 A kind of increment synchronization method, apparatus and system
CN108769212B (en) * 2018-05-31 2023-04-07 康键信息技术(深圳)有限公司 Data synchronization method and device, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105912949A (en) * 2016-04-13 2016-08-31 北京京东尚科信息技术有限公司 Data permission management method, data permission management system and service management system
CN106294075A (en) * 2016-08-17 2017-01-04 浪潮软件股份有限公司 A kind of SQL is monitored method, Apparatus and system
CN108205560A (en) * 2016-12-19 2018-06-26 腾讯科技(深圳)有限公司 A kind of method of data synchronization and device

Also Published As

Publication number Publication date
CN110347747A (en) 2019-10-18

Similar Documents

Publication Publication Date Title
WO2020248375A1 (en) Method and system for synchronizing data between databases, computer device and storage medium
CN109525990B (en) Wireless screen projection method and device, computer equipment and storage medium
WO2020151181A1 (en) Cross-platform data updating method and apparatus based on block chain, and computer device
US10051035B2 (en) Method and apparatus for providing secure file transmission
CN110932918B (en) Log data acquisition method and device and storage medium
US20130152069A1 (en) Method, apparatus and system for initiating terminal operation
WO2019051948A1 (en) Method, apparatus, server, and storage medium for processing monitoring data
CN113312064B (en) Method and device for installing and configuring physical machine and computer readable medium
CN110597918A (en) Account management method and device and computer readable storage medium
CN111177776A (en) Multi-tenant data isolation method and system
WO2022142153A1 (en) Electricity meter upgrading method and system, smart meter, and storage medium
CN102905000B (en) Address book synchronization method and device
WO2022179353A1 (en) Domain name resolution method and apparatus, and computer device
CN110460668B (en) File uploading method and device, computer equipment and storage medium
WO2016074412A1 (en) Compatibility administration method based on network configuration protocol, storage medium and device
CN111158711A (en) Application program deployment method and device for multiple android system terminals
CN109729121B (en) Cloud storage system and method for realizing custom data processing in cloud storage system
CN106933932B (en) Data processing method and device and application server
CN111367686A (en) Service interface calling method and device, computer equipment and storage medium
CN110661850A (en) Edge calculation method, system, computer equipment and storage medium
CN115510366A (en) Business message pushing method and device, computer equipment and storage medium
CN114020368A (en) Information processing method and device based on state machine and storage medium
CN113204558A (en) Method and device for automatically updating data table structure
CN108052380B (en) Business function docking method and device, computer equipment and storage medium
CN113992739B (en) Local area network OTA firmware upgrading device, method and system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19933005

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19933005

Country of ref document: EP

Kind code of ref document: A1