Database synchronization method and device

By automatically comparing and synchronizing database objects, the problem of inconsistent database table structures in multiple environments is solved, efficient and accurate database synchronization is achieved, and the risk of manual intervention and errors is reduced.

CN120744009APending Publication Date: 2025-10-03HUI ZE (CHENGDU) NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510926184.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-04
Publication Date
2025-10-03

AI Technical Summary

Technical Problem

During the development of enterprise information systems, inconsistent database table structures in multiple environments lead to data loss, business process interruptions and other problems. The existing manual comparison and synchronization methods are inefficient and prone to errors.

Method used

By obtaining the database synchronization requirements input by the user, determining the synchronization mode based on the identifiers of the source and target objects, searching for pre-configured synchronization rules, automatically comparing and synchronizing database objects, supporting single-table, whole-database, and full-instance synchronization modes, and using synchronization rules to detect structural differences and perform synchronization operations.

Benefits of technology

It significantly improves the efficiency of database synchronization, reduces manual intervention, lowers the risk of errors, and ensures accurate and efficient synchronization of data between different environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120744009A_ABST
    Figure CN120744009A_ABST
Patent Text Reader

Abstract

The invention discloses a database synchronization method and device, and relates to the technical field of databases. According to the database synchronization method, a database synchronization demand input by a user is obtained, the database synchronization demand comprises a source object identifier and a target object identifier, a source object and a target object are two database objects to be synchronized, a synchronization mode is determined according to the source object identifier and the target object identifier, and the type and range of synchronization operation are clarified. The pre-configured synchronization rule corresponding to the combination of the source object identifier and the target object identifier is searched, and the source object and the target object are synchronized based on the synchronization mode and the synchronization rule, so that the structure consistency of the target object and the source object is ensured, the synchronization efficiency is remarkably improved, the manual intervention is reduced, and the error risk is reduced. And accurate and efficient synchronization of data in different environments is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and more specifically, to a database synchronization method and device. Background Art

[0002] In the enterprise information system R&D system, the database serves as the core carrier for data storage and interaction, supporting the normal operation of various business systems. From the development environment, test environment to the production environment, the consistency of the database table structure is the key foundation for ensuring the stable operation of the system and the accurate flow of data. In the process of collaborative R&D in multiple environments, inconsistent database table structures will cause a series of problems. In serious cases, it may cause data loss in the production environment and interrupt business processes, affecting customer service quality and enterprise operational efficiency. Therefore, R&D personnel or database management personnel are required to compare and synchronize the database table structures of different environments to ensure the consistency of the table structures in the development, testing, and production environments. However, the current manual comparison and synchronization of database table structures in multiple environments by R&D personnel or database administrators has a series of significant drawbacks such as low efficiency, time-consuming and labor-intensive, and prone to errors. Summary of the Invention

[0003] In view of the above problems, this application proposes a database synchronization method and device to improve the efficiency of database synchronization. The specific solution is as follows:

[0004] In a first aspect, a database synchronization method includes:

[0005] Obtaining a database synchronization requirement input by a user, wherein the database synchronization requirement includes a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized;

[0006] Determine a synchronization mode according to the source object identifier and the target object identifier, wherein the synchronization mode is used to characterize the type and scope of the synchronization operation;

[0007] Searching for a pre-configured synchronization rule corresponding to a combination of the source object identifier and the target object identifier;

[0008] The source object and the target object are synchronized based on the synchronization mode and the synchronization rule.

[0009] In one possible design, in another implementation of the first aspect of the embodiments of the present application, the process of synchronizing the source object and the target object based on the synchronization mode and the synchronization rule includes:

[0010] The source object and the target object are compared based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object, and the target object is synchronized based on the difference result.

[0011] In one possible design, in another implementation of the first aspect of the embodiments of the present application, the synchronization mode includes a single-table synchronization mode, a whole-database synchronization mode, and a full-instance synchronization mode;

[0012] The process of determining the synchronization mode according to the source object identifier and the target object identifier includes:

[0013] If the source object identifier includes a source database instance identifier, a source database identifier, and a source data table identifier, and the target object identifier includes a target database instance identifier, a target database identifier, and a target data table identifier, then the synchronization mode is a single-table synchronization mode;

[0014] If the source object identifier includes a source database instance identifier and a source database identifier, and the target object identifier includes a target database instance identifier and a target database identifier, then the synchronization mode is the whole database synchronization mode;

[0015] If the source object identifier only includes the source database instance identifier, and the target object identifier only includes the target database instance identifier, then the synchronization mode is the full-instance synchronization mode.

[0016] In one possible design, in another implementation of the first aspect of the embodiments of the present application, performing a comparison operation on the source object and the target object based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object includes:

[0017] If the synchronization mode is the single-table synchronization mode, obtaining a source database and a source data table in the source database in the source database instance, and a target database and a target data table in the target database in the target database instance based on the synchronization rule, comparing the structures of the source data table and the target data table, and obtaining a difference result between the source data table and the target data table;

[0018] If the synchronization mode is the whole database synchronization mode, then based on the synchronization rules, the source database in the source database instance and the target database in the target database instance are obtained, each data table in the source database and each data table in the target database are traversed, the structures of each data table in the source database and each data table in the target database are compared, and the difference results between the source database and the target database are obtained;

[0019] If the synchronization mode is the full-instance synchronization mode, each non-system database in the source database instance and each non-system database in the target database instance are obtained based on the synchronization rules, and each non-system database in the source database instance is compared with each non-system database in the target database instance to obtain a difference result between the source database instance and the target database instance.

[0020] In one possible design, in another implementation of the first aspect of the embodiments of the present application, the synchronization rules include connection parameters of the source database instance, connection parameters of the target database instance, database mapping rules and table-level mapping rules, the database mapping rules are used to characterize the rules for synchronizing the source database to the target database, and the table-level mapping rules are used to characterize the rules for synchronizing the source data table to the target data table.

[0021] In one possible design, in another implementation of the first aspect of the embodiments of the present application, performing a synchronization operation on the target object based on the difference result includes:

[0022] If the difference result indicates that there is a difference in any one or more of the field information, index information, and constraint information of the table structure of the source object and the target object, synchronizing the table structure of the target object according to the table structure of the source object;

[0023] If the difference result indicates that the target object lacks a database or a data table corresponding to the source object, a database or a data table corresponding to the source object is created in the target object.

[0024] In one possible design, in another implementation of the first aspect of the embodiments of the present application, the process of obtaining a database synchronization requirement input by a user includes:

[0025] The response scheduling tool sends a synchronization instruction according to the configured time rule, and obtains the database synchronization requirement input by the user and stored in the configured storage database.

[0026] In one possible design, in another implementation of the first aspect of the embodiments of the present application, before responding to the synchronization instruction sent by the scheduling tool according to the configured time rule, the method further includes:

[0027] The database synchronization requirement input by the user based on the configured front-end interactive interface is obtained, the database synchronization requirement is transmitted to the back-end service, and the back-end service processes the database synchronization requirement and stores it in the storage database.

[0028] In one possible design, in another implementation of the first aspect of the embodiments of the present application, the method further includes:

[0029] A synchronization log is generated, where the synchronization log includes any one or more of the synchronization mode, source object identifier, target object identifier, synchronization time, number of successful synchronizations, and number of failed synchronizations.

[0030] In a second aspect, a database synchronization device is provided, comprising:

[0031] A synchronization requirement acquisition unit is used to acquire a database synchronization requirement input by a user, wherein the database synchronization requirement includes a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized;

[0032] a synchronization mode determining unit, configured to determine a synchronization mode according to the source object identifier and the target object identifier, wherein the synchronization mode is used to characterize the type and scope of a synchronization operation;

[0033] a synchronization rule determination unit, configured to search for a pre-configured synchronization rule corresponding to a combination of the source object identifier and the target object identifier;

[0034] A synchronization operation unit is used to synchronize the source object and the target object based on the synchronization mode and the synchronization rule.

[0035] Based on the above technical solution, the present application proposes a database synchronization method that obtains database synchronization requirements input by the user, including a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized. The method determines the synchronization mode based on the source object identifier and the target object identifier, and clarifies the type and scope of the synchronization operation. The method searches for pre-configured synchronization rules corresponding to the combination of the source object identifier and the target object identifier, and performs synchronization operations on the source object and the target object based on the synchronization mode and the synchronization rules, ensuring that the structure of the target object is consistent with that of the source object. This method significantly improves synchronization efficiency, reduces manual intervention, reduces the risk of errors, and ensures accurate and efficient synchronization of data between different environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:

[0037] Figure 1 A flowchart of a database synchronization method provided in an embodiment of the present application;

[0038] Figure 2 A system structure diagram of a database synchronization system provided in an embodiment of the present application;

[0039] Figure 3 A schematic diagram of the workflow of a database synchronization system provided in an embodiment of the present application;

[0040] Figure 4 A schematic diagram of the structure of a database synchronization device provided in an embodiment of the present application;

[0041] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] Before introducing the present application, some technical terms involved in the embodiments of the present application are first explained and described:

[0043] Database instance: A database instance is a specific entity running within a database management system. It can represent an independent operating environment, such as a development database instance for a development environment or a test database instance for a test environment. A database instance can contain multiple databases, and a database can contain multiple tables. Tables are the underlying data storage units used to store actual data.

[0044] DDL: Data Definition Language (DDL) is a set of statements in SQL (Structured Query Language) used to define and manage database structures. It is used to create, modify, and delete various database objects, such as databases, tables, views, and indexes. Using DDL statements, users can build and adjust the database schema, laying the foundation for data storage and management.

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

[0046] The terms "first", "second" etc. in the specification of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. Should be understood that the terms used in this way can be interchangeable in appropriate circumstances, and this is merely a way of distinguishing the objects of identical properties when describing them in the embodiments of the present application. In addition, the terms "comprise" and "have" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0047] This application can be applied to the development and management of enterprise information systems. The following describes the application scenario of this application using database management in multiple environments within the financial industry as an example. In the financial industry, databases serve as the core carrier for data storage and interaction, supporting the normal operation of various business systems. From development environments, test environments, to production environments, the consistency of database table structures is the key foundation for ensuring stable system operation and accurate data flow. The table structure defines the storage format, relationships, and business rules of data, and is the underlying architectural support for data interaction and system function implementation between different environments. During the collaborative development process of multiple environments, inconsistent database table structures can cause a series of serious problems. For example, if new business fields in the development environment are not synchronized to the test environment in a timely manner, test case execution failures and business logic verification deviations may occur. The absence of table indexes optimized in the test environment in the production environment can lead to inefficient data queries and even transaction response timeouts. Differences in foreign key constraints and field types between different environments can also lead to data synchronization errors and interface call anomalies. In severe cases, this can cause data loss in the production environment and interrupt business processes, impacting customer service quality and enterprise operational efficiency.

[0048] However, currently, R&D personnel or database administrators use manual methods to compare and synchronize database table structures across multiple environments. This method has significant drawbacks, such as low efficiency, prone to errors, and high operational risks, which seriously affect system stability and data accuracy. Manual comparison relies on administrators to review SQL scripts line by line or manually compare table structure elements such as fields, indexes, and constraints using graphical tools. For complex systems containing hundreds of tables, a single full comparison can take hours or even longer, and it is very easy to miss key changes due to visual fatigue or misunderstandings of the business. For example, if a new enumeration type field in the development environment is not synchronized to the test environment, it may cause the business logic verification to fail during the testing phase. The data type mismatch problem will not be exposed until the production environment is deployed, delaying the defect repair cycle. Manual synchronization requires administrators to perform script export, difference merging, syntax verification, segmented execution, and other operations in the development, test, and production environments in sequence. Command input errors at any stage in the process may lead to data loss or business interruption.

[0049] In order to achieve efficient comparison and synchronization of database table structures in multiple environments such as development environment, test environment and production environment, this application provides a database synchronization method to realize automatic comparison and synchronization of table structures, ensuring that the structure of target objects is consistent with that of source objects. This not only significantly improves synchronization efficiency and reduces manual intervention, but also reduces the risk of errors, ensuring accurate and efficient synchronization of data between different environments.

[0050] Next, see Figure 1 , Figure 1 A flowchart of a database synchronization method provided in an embodiment of the present application is as follows, specifically including the following steps:

[0051] Step S100: Obtain the database synchronization requirement input by the user.

[0052] Specifically, the database synchronization requirement input by the user is obtained. The database synchronization requirement includes a source object identifier and a target object identifier. The source object corresponding to the source object identifier and the target object corresponding to the target object identifier are the two database objects to be synchronized. The database synchronization requirement is used to clarify the database objects that the user wishes to synchronize. The source object identifier specifies the starting point of the synchronization operation, and the target object identifier specifies the end point of the synchronization operation. The target object is the database object that needs to be structurally compared with the source object and updated. The source object identifier and the target object identifier can be used to locate the database instance, database, or data table that needs to be synchronized, thereby providing clear guidance for subsequent table structure difference detection and synchronization operation execution, ensuring the accuracy and efficiency of the synchronization operation.

[0053] Step S110: Determine a synchronization mode according to the source object identifier and the target object identifier.

[0054] Specifically, the synchronization mode is used to characterize the type and scope of the synchronization operation, and the synchronization mode is determined based on the source object identifier and target object identifier input by the user. In an optional manner, the source object identifier includes but is not limited to the source database instance identifier, the source database identifier, and the source data table identifier, and the target object identifier includes but is not limited to the target database instance identifier, the target database identifier, and the target data table identifier. The synchronization mode is determined by analyzing the source object identifier and the target object identifier, and it is identified whether the synchronization operation the user wishes to perform is for a single table, the entire database, or the entire database instance. Through the synchronization mode determination mechanism based on the source object identifier and the target object identifier, it is possible to flexibly adapt to the synchronization needs of different users in different scenarios, and provide accurate implementation of synchronization operations, whether it is a synchronization operation on a single table or a comprehensive synchronization of the entire database instance.

[0055] Step S120: Search for a pre-configured synchronization rule corresponding to the combination of the source object identifier and the target object identifier.

[0056] Specifically, a pre-configured synchronization rule corresponding to the combination of the source object identifier and the target object identifier is searched. Alternatively, the synchronization rule can be searched in a synchronization information repository, which records the correspondence between the combination of the source object identifier and the target object identifier and the synchronization rule. Alternatively, the synchronization information repository can be a mapping table or a configuration file.

[0057] Step S130: Synchronize the source object and the target object based on the synchronization mode and the synchronization rule.

[0058] Specifically, you can synchronize the source and target objects based on the synchronization mode and synchronization rules to ensure that the target objects are consistent with the source objects, ensuring data consistency and system stability.

[0059] This embodiment obtains the database synchronization requirements input by the user, including the source object identifier and the target object identifier, where the source object and the target object are the two database objects to be synchronized, to ensure the flexibility and accuracy of the synchronization operation. The synchronization mode is determined based on the source object identifier and the target object identifier, and the type and scope of the synchronization operation are clarified. The pre-configured synchronization rules corresponding to the combination of the source object identifier and the target object identifier are searched, and the source object and the target object are synchronized based on the synchronization mode and the synchronization rules to ensure that the structure of the target object is consistent with that of the source object, significantly improve synchronization efficiency, reduce manual intervention, reduce the risk of errors, and ensure accurate and efficient synchronization of data between different environments.

[0060] Furthermore, in some embodiments of this application, synchronization modes may include single-table synchronization mode, whole-database synchronization mode, and full-instance synchronization mode. These three synchronization modes address different database synchronization requirements and can be determined based on the source and target object identifiers. These modes are described in detail below.

[0061] Single-table synchronization mode: If the source object identifier includes the source database instance identifier, source database identifier, and source data table identifier, and the target object identifier includes the target database instance identifier, target database identifier, and target data table identifier, the synchronization mode is determined to be single-table synchronization mode. In single-table synchronization mode, structural difference detection and synchronization operations are performed only on the specified single table, ensuring that the structural update of the single table is completed efficiently without affecting other tables. Single-table synchronization mode is suitable for scenarios where users perform targeted maintenance or updates on a specific table, such as synchronizing a data table with a newly added field in a development environment.

[0062] Whole-database synchronization mode: If the source object identifier includes the source database instance identifier and source database identifier, and the target object identifier includes the target database instance identifier and target database identifier, the synchronization mode is determined to be whole-database synchronization mode. When users need to perform a unified structural update on all tables in an entire database, the system automatically traverses every table in the specified database, detects structural differences in each table, and synchronizes them, achieving a unified update of the entire database structure. Whole-database synchronization mode is suitable for scenarios where users are migrating or upgrading a database as a whole, such as synchronizing an optimized database structure from a test environment to a production environment.

[0063] Full-instance synchronization mode: If the source object identifier only includes the source database instance identifier, and the target object identifier only includes the target database instance identifier, the synchronization mode is determined to be full-instance synchronization mode. When the user needs to synchronize all non-system databases in the entire database instance, all non-system databases in the source database instance can be scanned and compared with the target instance, automatically identifying and synchronizing the table structure differences of all non-system databases, and achieving comprehensive structural synchronization between the two database instances. Full-instance synchronization mode is suitable for scenarios where the overall consistency of multi-environment database instances must be maintained, such as performing large-scale table structure synchronization operations between development, test, and production environments.

[0064] This embodiment uses a synchronization mode determination mechanism based on source object identifiers and target object identifiers to flexibly adapt to the synchronization needs of different users in different scenarios. Whether it is the refined operation of a single table or the comprehensive synchronization of the entire database instance, it can provide efficient and accurate solutions, thereby ensuring the consistency and stability of the multi-environment database table structure.

[0065] Furthermore, in some embodiments of the present application, the source object identifier and the target object identifier are used to obtain corresponding synchronization rules in the configured synchronization information library. The synchronization rules can cover information at multiple levels to ensure that the synchronization process can be carried out according to the preset logic and requirements. This part of the content is introduced in detail below.

[0066] In an optional manner, the synchronization rules may include but are not limited to connection parameters of the source database instance, connection parameters of the target database instance, database mapping rules, and table-level mapping rules.

[0067] Source database instance connection parameters: These define how to connect to the source database instance. These parameters include the source database instance's IP address, port number, and database name. Using these parameters, you can successfully establish communication with the source database instance and obtain its table structure information, providing the data foundation for subsequent comparison and synchronization operations.

[0068] Target database instance connection parameters: These define how to connect to the target database instance. These parameters include the target database instance's IP address, port number, and database name. Using these parameters, you can establish a connection to the target database instance and apply the synchronized table structure to the target database, ensuring that the target object's table structure remains consistent with the source object.

[0069] Database mapping rules: Database mapping rules describe the rules for synchronizing a source database with a target database. In multi-environment database synchronization scenarios, the source and target databases may differ in name, structure, or other properties. Database mapping rules define how the data structure in the source database is mapped to the target database, ensuring that the source database structure is correctly mapped to the target database during synchronization.

[0070] Table-level mapping rules: Table-level mapping rules describe the rules for synchronizing a source table with a target table. In practice, the source and target tables may differ in field definitions, index structures, constraints, and other aspects. Table-level mapping rules define how to map structural elements such as fields, indexes, and constraints in the source table to the target table. This ensures that the structure of the source table is correctly mapped to the target table during synchronization.

[0071] This embodiment uses synchronization rules to flexibly handle a variety of complex synchronization scenarios, from simple table structure synchronization to complex cross-environment and cross-database instance synchronization operations. Synchronization rules not only ensure the accuracy of synchronization operations but also improve automation and adaptability, efficiently completing database table structure synchronization tasks in different environments and under different requirements.

[0072] Furthermore, in some embodiments of the present application, a synchronization operation of the source object and the target object may be performed based on the comparison result of the source object and the target object. This part is described in detail below.

[0073] An optional approach involves comparing the source and target objects based on a defined synchronization mode and rules. This allows for identification of any structural differences between the source and target objects, generating a diff result between the source and target objects, and then synchronizing the target object based on the diff result to ensure consistency with the source object. This comparison and synchronization mechanism, based on synchronization modes and rules, enables efficient and accurate synchronization between source and target objects.

[0074] Furthermore, in some embodiments of the present application, the source object and the target object may be compared based on different synchronization modes and synchronization rules to obtain difference results between the source object and the target object. This part is described in detail below.

[0075] If the synchronization mode is single-table, the system connects to the source database instance based on the source database instance connection parameters in the synchronization rule and locates the source database and the specified source table within that source database. It also connects to the target database instance based on the target database instance connection parameters in the synchronization rule and locates the target database and the target table within that target database. The system identifies and matches the source and target tables based on the database and table-level mapping rules in the synchronization rule. Optionally, the system performs a detailed field-by-field, index-by-index, and constraint-by-constraint comparison of the source and target tables based on the synchronization rule. Optionally, the system compares up to 21 structural elements, including fields (type, length, default value), constraints (primary keys, foreign keys, indexes), and objects (views, stored procedures). This includes field attributes such as field name, data type, length, precision, and nullability, as well as index types, index fields, primary key constraints, foreign key constraints, and unique constraints. This comparison identifies any structural differences between the source and target tables.

[0076] If the synchronization mode is whole-database synchronization mode, you can connect to the source database instance according to the connection parameters of the source database instance in the synchronization rules, locate the source database in the source database instance, and obtain all the data tables in the source database. At the same time, you can also connect to the target database instance according to the connection parameters of the target database instance in the synchronization rules, locate the target database in the target database instance, and obtain all the data tables in the target database. You can automatically traverse all data tables in the source and target databases to determine whether the target database contains all the data tables corresponding to the source database, and perform a structural comparison for each pair of corresponding data tables. This includes not only comparing the fields in the tables, but also a comprehensive comparison of structural elements such as indexes and constraints. Through table-by-table comparison, the difference results between the entire source and target databases are obtained.

[0077] If the synchronization mode is full-instance synchronization mode, you can connect to the source database instance according to the source database instance connection parameters in the synchronization rules, connect to the target database instance according to the target database instance connection parameters, and locate all non-system databases in the source database instance to obtain all data tables in each non-system database of the source database instance. You can also locate all non-system databases in the target database instance and obtain all data tables in each non-system database of the target database instance. You can identify and match the various non-system databases in the source and target database instances according to the database mapping rules in the synchronization rules. Then, you can perform a one-by-one comparison of each corresponding database in the source and target database instances, including all table structures in the databases. This process involves a comprehensive field-by-field, index-by-index, and constraint-by-constraint comparison of all tables in each database to identify structural differences in all databases between the two database instances. Ultimately, the difference results between the source and target database instances are obtained.

[0078] This embodiment flexibly adapts to synchronization requirements at varying granularities through a comparison and synchronization mechanism based on synchronization modes and synchronization rules. Whether synchronizing a single table, an entire database, or a full instance, it provides efficient and accurate difference detection and synchronization solutions. This not only increases the automation level of synchronization operations but also significantly reduces the risk of manual intervention, ensuring the consistency and stability of database table structures across multiple environments.

[0079] Furthermore, in some embodiments of the present application, a synchronization operation may be performed on the target object based on the difference result to ensure the consistency between the source object and the target object. This part is described in detail below.

[0080] If the difference result indicates that the table structures of the source object and the target object differ in any one or more of field information, index information, and constraint information, the table structure of the target object will be synchronized according to the table structure of the source object. If there are differences in fields between the source object's data table and the target object's data table, such as inconsistencies in field type, length, precision, default value, or whether it is nullable, you can modify or update the fields of the corresponding data table in the target object based on the field information of the source object's data table to ensure consistency of field information; if there are differences in index structure between the source object's data table and the target object's data table, such as inconsistencies in index type, index field, or index name, you can create or delete the index of the corresponding data table in the target object based on the index information of the source object's data table to ensure consistency of index information; if there are differences in constraints between the source object's data table and the target object's data table, such as inconsistencies in primary key constraints, foreign key constraints, unique constraints, or check constraints, you can add or delete constraints in the corresponding data table in the target object based on the constraint information of the source object's data table to ensure consistency of constraint information and adjust the table structure of the target object to make it consistent with the table structure of the source object, thereby ensuring the correctness of data interaction and business logic. An optional method is to automatically generate corresponding DDL statements for detected differences, such as ALTER TABLE statements for modifying table structures and ADD INDEX for adding indexes, to achieve automatic synchronization of table structures and ensure that the table structures of the target database remain consistent with those of the source database.

[0081] If the difference result indicates that the target object lacks the database or data table corresponding to the source object, you can create the corresponding database or data table in the target object. If the target database instance lacks the database corresponding to the source database instance, you can generate a "CREATE DATABASE" statement based on the definition of the missing database and execute it to create the missing database in the target object. This ensures that the target database instance has the database corresponding to the source database instance, providing a foundation for subsequent table structure synchronization.

[0082] If the target database lacks a table corresponding to the source database, you can generate a "CREATE TABLE" statement based on the structure definition of the source data table and execute the statement to create the missing data table in the target object. Ensure that the target database has a corresponding data table in the source database and that the structure of the data table is consistent with the source data table, including field definitions, index structure, and constraints.

[0083] This embodiment synchronizes the target object through the difference results, which can not only handle the differences in table structure, but also automatically create missing databases and data tables, thereby achieving comprehensive structural synchronization between the source object and the target object, significantly improving the automation level of the synchronization operation, reducing the need for manual intervention, and at the same time reducing the risk of errors caused by manual operations, eliminating spelling errors, syntax adaptation and other problems in manually written scripts, and ensuring the consistency and stability of the multi-environment database table structure.

[0084] Furthermore, in some embodiments of the present application, the database synchronization requirement input by the user may be obtained by receiving a synchronization instruction, which is described in detail below.

[0085] In the database synchronization system of this application, obtaining the database synchronization requirements input by the user is a key initial step, which ensures that the system can accurately execute the synchronization tasks specified by the user. This process involves the collaborative work of multiple components, as follows:

[0086] The database synchronization scheduling tool can periodically trigger synchronization operations based on preset time rules. When the scheduling tool sends synchronization instructions based on the configured time rules, it can respond to the synchronization instructions by searching the configured storage database for database synchronization requests entered by users through the front-end interactive interface and transmitting these requests to the back-end service. After receiving the database synchronization requests sent by the front-end, the back-end service will perform validation and data parsing. After processing is complete, the back-end service will enter the database synchronization requests into the configured storage database. Optionally, the storage database can be a MySQL database.

[0087] In this embodiment, when the scheduling tool triggers synchronization operations based on preset time rules, it retrieves the user's pre-entered database synchronization requirements from the storage database and executes the corresponding synchronization tasks based on the database synchronization requirements. This not only improves the system's automation level, but also ensures the accuracy and reliability of synchronization operations, significantly reducing the need for manual intervention.

[0088] Furthermore, in some embodiments of the present application, a synchronization log may be generated to provide users with a comprehensive record of operations and a basis for troubleshooting. This part is described in detail below.

[0089] Generated logs may include the synchronization mode, source object ID, target object ID, synchronization time, number of successful synchronizations, number of failed synchronizations, and difference results. The synchronization mode records the mode used for the synchronization operation, such as single-table synchronization, whole-database synchronization, or full-instance synchronization, helping users understand the scope and granularity of the synchronization operation. The synchronization time can include the start and end times of the synchronization operation, as well as the total duration of the synchronization process, to assess the efficiency and performance of the synchronization operation. The number of successful synchronizations counts the number of database objects successfully synchronized during the synchronization operation, such as the number of tables or databases successfully synchronized, providing users with the overall success rate of the synchronization operation. The number of failed synchronizations counts the number of database objects that failed to synchronize during the synchronization operation and records the specific reasons for the failure, helping users quickly locate the problem and facilitate subsequent troubleshooting and repair. The difference results may include structural differences between the source and target objects detected during the synchronization operation, including differences in field information, index information, and constraint information. This provides users with a concrete basis for the synchronization operation and facilitates manual intervention or adjustments when necessary.

[0090] This embodiment not only improves the transparency of synchronization operations by generating a synchronization log containing the above information, but also provides users with comprehensive operation records and problem troubleshooting basis, which can help users better monitor the synchronization process, promptly discover and solve possible problems, thereby ensuring the accuracy and reliability of database table structure synchronization.

[0091] Furthermore, in some embodiments of the present application, the database synchronization method of the present application can be implemented by a database synchronization system deployed on a terminal device, which can be a mobile phone, a computer, a server, etc. Figure 2 , Figure 2 This is a system structure diagram of a database synchronization system provided in an embodiment of the present application. This part of the content is introduced in detail below.

[0092] As an optional approach, the database synchronization system can include front-end services, back-end services, a storage database, a scheduling tool, a main control module, a database connection module, a metadata acquisition module, a synchronization logic module, a configuration module, and a log module. The database synchronization system can adopt a front-end and back-end separation structure design, with front-end services and back-end services as the data interaction bridge, combined with the scheduling tool's timing scheduling mechanism, the storage database, and various modules to achieve database synchronization in multiple environments.

[0093] Front-end service: Node.js can be combined with the Express framework to build a user interaction interface. The user interaction interface serves as the entry point for user interaction and is responsible for receiving database synchronization requirements entered by users. It can interact with user terminals through a standardized RESTful API interface, perform preliminary processing and encapsulation of the database synchronization requirements entered by users, and transmit them to the back-end service in the form of HTTP requests, providing the entire system with a friendly user operation interface and a convenient data input channel.

[0094] Backend services: Receive database synchronization requests from the frontend service, perform validation and data parsing, and then store these requests in a storage database. Backend services can be developed using the Python Flask framework. Through defined interface specifications, they seamlessly integrate with various modules, ensuring smooth data flow between them.

[0095] Scheduling Tool: An optional method is to use crontab as a scheduling tool to periodically trigger synchronization operations according to preset time rules. By configuring flexible scheduling strategies, you can set different synchronization frequencies based on actual needs, ensuring timely and accurate comparison and synchronization, improving system automation and operational efficiency.

[0096] Storage Database: This database is used to store information related to database tables in multiple environments, including but not limited to database instance connection information, synchronization rules, database name, table name, and whether mapping relationships are enabled. It provides stable data storage and query services for front-end services, back-end services, and various modules, ensuring the security and integrity of system data.

[0097] Main Control Module: The "main()" function in the Main Control Module is responsible for obtaining database synchronization requirements entered by the user. Based on these requirements, the Main Control Module branches into different logical processing flows. In different synchronization scenarios, it verifies the validity of table names, then calls relevant modules to obtain the structural information of the source and target objects, performing difference comparisons and synchronization operations. Furthermore, the Main Control Module coordinates the workflow between modules, ensuring the orderly execution of each step, including the metadata acquisition module, difference comparison module, and synchronization execution module.

[0098] Database connection module: The database connection module can contain two functions: "get_db_connection()" and "close_db_connection()." The database connection module manages the lifecycle of database connections. The database connection module loads the connection parameters for the source and target database instances from the configuration module. Depending on the database instance type (which can include MySQL, Oracle, and others), the corresponding database driver is used to establish a database connection. During the connection establishment process, the database connection module can validate the connection parameters, such as verifying the correctness of the username and password, checking for network connectivity, and handling any errors to ensure connection stability and reliability. Alternatively, the database connection module can call the "get_db_connection()" function to establish connections to the source and target database instances, respectively. Once the database operation is completed, the database connection module can promptly close the database connection, freeing up system resources and preventing resource leaks, thereby ensuring the efficient operation of the entire synchronization system.

[0099] Metadata Acquisition Module: The metadata acquisition module can include the "get_non_system_databases()" function, which retrieves a list of non-system databases in the source database instance. The metadata acquisition module executes a specific SQL statement (for example, the "SHOW DATABASES" statement in MySQL) to retrieve the names of all databases. It then filters out system default databases, such as "information_schema," "mysql," "performance_schema," and "sys," ultimately returning a user-defined list of non-system databases. This provides database-level metadata for both full-instance and full-database synchronization modes, ensuring precise identification of the databases that require synchronization. The module can also include the "get_table_structure()" function, which retrieves the structure of a specified table in a specified database. This function retrieves table structure data, including field information, index information, and constraint information, by executing the "DESCRIBE TABLE" statement. The retrieved structure data can be returned in a structured format (such as a dictionary or object), providing the foundation for subsequent table structure comparisons and accurately identifying differences between the source and target tables.

[0100] Synchronization Logic Module: The synchronization logic module can include the "sync_missing_tables()" function. After comparing the table lists of the source and target databases, if any tables are missing from the target database, this function generates a "CREATE TABLE" statement based on the corresponding table structure in the source database and calls the "execute_ddl_statements()" function to execute the statement in the target database. This automatically creates the missing tables, ensuring that the table structure in the target database fully reflects the structure of the source database. Even if some tables in the target database are accidentally deleted or omitted, they can be restored through synchronization. The "create_database_if_not_exists()" function can also be included. This function checks whether the database corresponding to the source database instance exists in the target database instance. If not, it generates a "CREATE DATABASE" statement and executes it to create the database. This ensures that the corresponding database exists in the target database instance when performing full-database synchronization or full-instance synchronization. This provides the necessary foundation for subsequent table structure synchronization and avoids synchronization failures caused by the target database not existing.

[0101] In an optional manner, the synchronization logic module may also include a "compare_table_structures()" function, which uses a difference comparison algorithm to compare the structures of the source object and the target object part by part to generate difference results, where the difference results can be a difference report. The difference report provides a basis for generating DDL statements, and can accurately know what modifications need to be made to the target table structure to make it consistent with the source table structure. The synchronization logic module may also include an "execute_ddl_statements()" function, which is responsible for executing the generated DDL statements in the target database. Before execution, it can perform syntax verification and security checks on the DDL statements to ensure the correctness and security of the statements. Through the connection established by the database connection module, the DDL statements are sent to the target object for execution, and abnormal situations during the execution process are handled and the execution results are recorded. This ensures that the DDL statements can be executed correctly, thereby achieving synchronous updates of the table structure and making the target object consistent with the source object.

[0102] Configuration module: This module is responsible for storing the credential information of the database instance, that is, the connection parameters. In order to ensure the security of the connection parameters, it uses a secure storage method, such as encrypted storage. In addition, it also obtains the synchronization rules through the "get_instance_mapping_from_c()" function. This function reads the pre-defined synchronization rules from the synchronization information library and returns them in the form of structured data to guide the execution of the synchronization process, ensuring that the relationship between the source database instance and the target database instance can be accurately identified and matched, thereby achieving efficient synchronization operations. An optional method is to obtain the synchronization rules through the interface provided by the configuration module to provide guidance for subsequent database connections and synchronization operations.

[0103] Logging Module: The logging module includes a "setup_logger()" function, which configures the log format, including but not limited to the timestamp, log level, module name, and log information. This ensures clear, standardized logging, making it easy to review and analyze. It provides logging capabilities at different levels, such as DEBUG, INFO, WARNING, and ERROR, recording information such as database connection status, synchronization mode selection, difference comparison results, and DDL statement execution status. Logging enables real-time monitoring of operating status and rapid problem identification when anomalies occur, providing strong support for system maintenance and optimization.

[0104] This embodiment provides an efficient, automated and flexible database synchronization system, which significantly improves the efficiency and reliability of table structure synchronization of multi-environment databases through the front-end and back-end separation architecture design, timing scheduling mechanism and various modules. The front-end service provides users with a friendly interactive interface to facilitate users to input database synchronization requirements. The back-end service is responsible for data processing and verification to ensure that the data is accurately entered into the storage database. The storage database centrally manages multi-environment database information and provides stable data support. The scheduling tool implements flexible timing scheduling and can set the synchronization frequency according to actual needs, reduce manual intervention and improve the degree of automation. Supports multiple synchronization modes to ensure the accuracy and reliability of synchronization operations. The database synchronization system of this embodiment not only significantly improves synchronization efficiency and reduces manual intervention, but also reduces the risk of errors, ensuring accurate and efficient synchronization of data between different environments.

[0105] Furthermore, in some embodiments of the present application, the workflow of the database synchronization system may also be introduced, see Figure 3 , Figure 3 This is a schematic diagram of the workflow of a database synchronization system provided in an embodiment of the present application. This part of the content is introduced in detail below.

[0106] The database synchronization system first obtains the user's database synchronization requirements, including the source and target object identifiers entered by the user. Subsequently, the corresponding synchronization rules are determined based on the combination of the source and target object identifiers. Next, a database instance connection is established based on the synchronization rules, establishing connections to both the source and target database instances. Based on the database synchronization requirements, the synchronization mode is determined, determining whether it is single-table synchronization, entire database synchronization, or full-instance synchronization. The steps of determining the synchronization mode and determining the synchronization rules are not sequential; the synchronization mode determination step can be performed first, followed by the steps of determining the synchronization rules and establishing the database instance connection. After the synchronization mode is determined, the steps of comparing and generating synchronization statements are executed. This involves performing a detailed comparison of the source and target objects and generating the corresponding synchronization statements based on the comparison results. These synchronization statements can be DDL statements, which modify the table structure of the target database to align with that of the source database. After the synchronization statements are generated, the synchronization operation can be executed to align the target objects with the source objects. Finally, the synchronization results are recorded and a synchronization log is generated for easy review and analysis, ensuring traceability and transparency of the synchronization operation.

[0107] The database synchronization system of this embodiment significantly improves the efficiency and accuracy of synchronization operations through automated processes, enhances operational traceability and transparency, facilitates user monitoring and analysis of the synchronization process, ensures the consistency of source and target objects, and ensures system stability. By replacing manual line-by-line comparisons, the time required for difference analysis of a single batch of 34,000 tables was reduced from over 900 minutes to under 10 minutes, achieving an efficiency improvement of over 90 times. This solves the problem of time-consuming manual comparisons and reduces the missed detection rate from 22% to under 0.5%. Automated comparisons cover details that are easily overlooked by humans (such as differences in default values ​​and index sorting rules), enabling comprehensive and accurate identification of structural differences. The time required for single-environment table structure synchronization was reduced from 15 hours to 8 minutes, significantly reducing manual intervention costs. The risk of execution failure due to script syntax errors, incorrect foreign key dependency order, and environment configuration mismatches was reduced by over 90%, and the script execution success rate was increased from 78% to 99.5%, achieving automation of the synchronization process.

[0108] The above describes a database synchronization method provided by an embodiment of the present application. The following describes an apparatus for executing the above database synchronization method.

[0109] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of a database synchronization device provided in an embodiment of the present application. Figure 4 As shown, the database synchronization device includes:

[0110] The synchronization requirement acquisition unit 11 is used to acquire a database synchronization requirement input by a user, wherein the database synchronization requirement includes a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized;

[0111] a synchronization mode determining unit 12, configured to determine a synchronization mode according to the source object identifier and the target object identifier, wherein the synchronization mode is used to characterize the type and scope of a synchronization operation;

[0112] a synchronization rule determination unit 13, configured to search for a pre-configured synchronization rule corresponding to a combination of the source object identifier and the target object identifier;

[0113] The synchronization operation unit 14 is configured to perform a synchronization operation on the source object and the target object based on the synchronization mode and the synchronization rule.

[0114] In a possible implementation, the process of the synchronization operation unit 14 performing a synchronization operation on the source object and the target object based on the synchronization mode and the synchronization rule includes:

[0115] The source object and the target object are compared based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object, and the target object is synchronized based on the difference result.

[0116] In a possible implementation, the synchronization mode includes a single-table synchronization mode, a whole-database synchronization mode, and a full-instance synchronization mode. The process of the synchronization mode determination unit 12 determining the synchronization mode according to the source object identifier and the target object identifier includes:

[0117] If the source object identifier includes a source database instance identifier, a source database identifier, and a source data table identifier, and the target object identifier includes a target database instance identifier, a target database identifier, and a target data table identifier, then the synchronization mode is a single-table synchronization mode;

[0118] If the source object identifier includes a source database instance identifier and a source database identifier, and the target object identifier includes a target database instance identifier and a target database identifier, then the synchronization mode is the whole database synchronization mode;

[0119] If the source object identifier only includes the source database instance identifier, and the target object identifier only includes the target database instance identifier, then the synchronization mode is the full-instance synchronization mode.

[0120] In a possible implementation, the synchronization operation unit 14 performs a comparison operation on the source object and the target object based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object, including:

[0121] If the synchronization mode is the single-table synchronization mode, obtaining a source database and a source data table in the source database in the source database instance, and a target database and a target data table in the target database in the target database instance based on the synchronization rule, comparing the structures of the source data table and the target data table, and obtaining a difference result between the source data table and the target data table;

[0122] If the synchronization mode is the whole database synchronization mode, then based on the synchronization rules, the source database in the source database instance and the target database in the target database instance are obtained, each data table in the source database and each data table in the target database are traversed, the structures of each data table in the source database and each data table in the target database are compared, and the difference results between the source database and the target database are obtained;

[0123] If the synchronization mode is the full-instance synchronization mode, each non-system database in the source database instance and each non-system database in the target database instance are obtained based on the synchronization rules, and each non-system database in the source database instance is compared with each non-system database in the target database instance to obtain a difference result between the source database instance and the target database instance.

[0124] In one possible implementation, the synchronization rules include connection parameters of the source database instance, connection parameters of the target database instance, database mapping rules, and table-level mapping rules. The database mapping rules are used to characterize the rules for synchronizing the source database to the target database, and the table-level mapping rules are used to characterize the rules for synchronizing the source data table to the target data table.

[0125] In a possible implementation, performing a synchronization operation on the target object based on the difference result includes:

[0126] If the difference result indicates that there is a difference in any one or more of the field information, index information, and constraint information of the table structure of the source object and the target object, synchronizing the table structure of the target object according to the table structure of the source object;

[0127] If the difference result indicates that the target object lacks a database or a data table corresponding to the source object, a database or a data table corresponding to the source object is created in the target object.

[0128] In a possible implementation, the process of the synchronization requirement obtaining unit 11 obtaining the database synchronization requirement input by the user includes:

[0129] The response scheduling tool sends a synchronization instruction according to the configured time rule, and obtains the database synchronization requirement input by the user and stored in the configured storage database.

[0130] In one possible implementation, a database synchronization device according to an embodiment of the present application further includes:

[0131] The synchronization requirement storage unit is used to obtain the database synchronization requirement input by the user based on the configured front-end interactive interface before the synchronization requirement acquisition unit 11 processes it, transmit the database synchronization requirement to the back-end service, and store it in the storage database after the back-end service processes the database synchronization requirement.

[0132] In one possible implementation, a database synchronization device according to an embodiment of the present application further includes:

[0133] The synchronization log generating unit is used to generate a synchronization log, wherein the synchronization log includes any one or more of the synchronization mode, source object identifier, target object identifier, synchronization time, number of successful synchronizations, and number of failed synchronizations.

[0134] An electronic device is also provided in an embodiment of the present application. Figure 5 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include, but is not limited to, fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.

[0135] like Figure 5 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes based on programs stored in a read-only memory (ROM) 602 or programs loaded from a storage device 608 into a random access memory (RAM) 603. When the electronic device is powered on, the RAM 603 also stores various programs and data required for the operation of the electronic device. The processing device 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0136] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a memory card, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Figure 5 The electronic device is shown with various devices, but it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed instead.

[0137] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.

[0138] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.

[0139] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0140] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the embodiments of the present application, the meaning of "plurality" is at least two, for example, two, three, etc., unless otherwise clearly specified.

[0141] In the embodiments of this application, unless otherwise specified or limited, terms such as "installed," "connected," "connected," and "fixed" should be understood in a broad sense. For example, they can refer to fixed connections, detachable connections, or integration; mechanical connections, electrical connections, or communication between them; direct connections, indirect connections through an intermediate medium, and internal connections between two components or interactions between two components, unless otherwise specified. Those skilled in the art will understand the specific meanings of the above terms in this application based on specific circumstances.

[0142] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

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

Claims

1. A database synchronization method, characterized in that: include: Obtaining a database synchronization requirement input by a user, wherein the database synchronization requirement includes a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized; Determine a synchronization mode according to the source object identifier and the target object identifier, wherein the synchronization mode is used to characterize the type and scope of the synchronization operation; Searching for a pre-configured synchronization rule corresponding to a combination of the source object identifier and the target object identifier; The source object and the target object are synchronized based on the synchronization mode and the synchronization rule.

2. The method according to claim 1, characterized in that The process of synchronizing the source object and the target object based on the synchronization mode and the synchronization rule includes: The source object and the target object are compared based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object, and the target object is synchronized based on the difference result.

3. The method according to claim 2, characterized in that The synchronization modes include single table synchronization mode, whole database synchronization mode and full instance synchronization mode; The process of determining the synchronization mode according to the source object identifier and the target object identifier includes: If the source object identifier includes a source database instance identifier, a source database identifier, and a source data table identifier, and the target object identifier includes a target database instance identifier, a target database identifier, and a target data table identifier, then the synchronization mode is a single-table synchronization mode; If the source object identifier includes a source database instance identifier and a source database identifier, and the target object identifier includes a target database instance identifier and a target database identifier, then the synchronization mode is the whole database synchronization mode; If the source object identifier only includes the source database instance identifier, and the target object identifier only includes the target database instance identifier, then the synchronization mode is the full-instance synchronization mode.

4. The method according to claim 3, characterized in that Comparing the source object and the target object based on the synchronization mode and the synchronization rule to obtain a difference result between the source object and the target object includes: If the synchronization mode is the single-table synchronization mode, obtaining a source database and a source data table in the source database in the source database instance, and a target database and a target data table in the target database in the target database instance based on the synchronization rule, comparing the structures of the source data table and the target data table, and obtaining a difference result between the source data table and the target data table; If the synchronization mode is the whole database synchronization mode, then based on the synchronization rules, the source database in the source database instance and the target database in the target database instance are obtained, each data table in the source database and each data table in the target database are traversed, the structures of each data table in the source database and each data table in the target database are compared, and the difference results between the source database and the target database are obtained; If the synchronization mode is the full-instance synchronization mode, each non-system database in the source database instance and each non-system database in the target database instance are obtained based on the synchronization rules, and each non-system database in the source database instance is compared with each non-system database in the target database instance to obtain a difference result between the source database instance and the target database instance.

5. The method according to claim 1, wherein The synchronization rules include the connection parameters of the source database instance, the connection parameters of the target database instance, database mapping rules and table-level mapping rules. The database mapping rules are used to characterize the rules for synchronizing the source database to the target database, and the table-level mapping rules are used to characterize the rules for synchronizing the source data table to the target data table.

6. The method according to claim 2, characterized in that Performing a synchronization operation on the target object based on the difference result includes: If the difference result indicates that there is a difference in any one or more of the field information, index information, and constraint information of the table structure of the source object and the target object, synchronizing the table structure of the target object according to the table structure of the source object; If the difference result indicates that the target object lacks a database or a data table corresponding to the source object, a database or a data table corresponding to the source object is created in the target object.

7. The method according to claim 1, characterized in that The process of obtaining database synchronization requirements input by users includes: The response scheduling tool sends a synchronization instruction according to the configured time rule, and obtains the database synchronization requirement input by the user and stored in the configured storage database.

8. The method according to claim 7, characterized in that Before responding to the synchronization instruction sent by the scheduling tool according to the configured time rules, it also includes: The database synchronization requirement input by the user based on the configured front-end interactive interface is obtained, the database synchronization requirement is transmitted to the back-end service, and the back-end service processes the database synchronization requirement and stores it in the storage database.

9. The method according to any one of claims 1 to 8, characterized in that Also includes: A synchronization log is generated, where the synchronization log includes any one or more of the synchronization mode, source object identifier, target object identifier, synchronization time, number of successful synchronizations, and number of failed synchronizations.

10. A database synchronization device, characterized in that: include: A synchronization requirement acquisition unit is used to acquire a database synchronization requirement input by a user, wherein the database synchronization requirement includes a source object identifier and a target object identifier, where the source object and the target object are two database objects to be synchronized; a synchronization mode determining unit, configured to determine a synchronization mode according to the source object identifier and the target object identifier, wherein the synchronization mode is used to characterize the type and scope of a synchronization operation; a synchronization rule determination unit, configured to search for a pre-configured synchronization rule corresponding to a combination of the source object identifier and the target object identifier; A synchronization operation unit is used to synchronize the source object and the target object based on the synchronization mode and the synchronization rule.