Method and device for synchronizing MySql data to database and medium
By determining the configuration information of the main table and child tables, creating index fields, and monitoring change information during the MySQL data synchronization process, the problems of poor synchronization effect and storage timeliness when MySQL data is synchronized to ES are solved, achieving efficient and accurate data synchronization and reducing system maintenance costs.
Patent Information
- Application Number
- CN202411377700.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-07
AI Technical Summary
In existing technologies, the synchronization effect of MySQL data to Elasticsearch (ES) is poor, and there are problems such as poor data storage timeliness and high polling pressure.
By determining the configuration information of the main and sub-tables in MySQL data, index fields are created for the preset database, and change information is monitored. The change information is then synchronized to the preset database based on the index fields.
It improves the accuracy of data synchronization, reduces system maintenance costs, and enhances the query flexibility and data synchronization efficiency of Elasticsearch.
Smart Images

Figure CN119271742A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method, a device and a medium for synchronizing MySql data to a database in the technical field of data processing. Background Art
[0002] The relational database management system (MySql) plays an important role in the business database, supporting the stable operation of the system. However, with the rapid growth of data volume, the query complexity between the main table and its associated sub-tables continues to increase, and relying solely on MySql for efficient data retrieval is becoming increasingly difficult. In order to effectively alleviate this situation, a search server (Elasticsearch, ES) is usually introduced as a query database. ES has become an ideal choice for handling complex query requirements with its excellent search performance, flexible data model and strong scalability.
[0003] In the related art, after obtaining the data change event of MySql, the data is sent to the ES database. In this way, the timeliness of data storage is poor, there is a certain polling pressure on the database, and synchronous deletion cannot be achieved, resulting in poor data synchronization effect. Summary of the invention
[0004] In order to solve the technical problem of poor synchronization effect of synchronizing MySql data to ES in the prior art, the purpose of the present invention is to provide a method, device and medium for synchronizing MySql data to a database. The technical solution adopted is as follows: In a first aspect, an embodiment of the present invention provides a method for synchronizing MySql data to a database, the method comprising: Determine the configuration information of the main table and sub-table of the relational database management system MySql data; Based on the configuration information of the main table and the sub-table, create an index field of a preset database; Monitor the change information of the main table and the sub-table; Based on the index field of the preset database, the change information is synchronized to the preset database.
[0005] In combination with the first aspect above, in some possible implementations, determining the configuration information of the main table and the sub-table of the MySql data includes: Determine the name information and business primary key of the main table and subtable of the MySql data; Based on the name information and the business primary key, configuration information of the main table and the sub-table is determined.
[0006] In combination with the first aspect, in some possible implementations, creating an index field of a preset database based on the configuration information of the main table and the sub-table includes: Get the address and account information of the preset database; Based on the address and account information of the preset database, query the field names and field types of the main table and the sub-table in the configuration information of the main table and the sub-table; Determine the primary field of the preset database based on the field name and field type of the primary table; Based on the field name and field type of the sub-table and the main field of the preset database, an index field of the preset database is constructed.
[0007] In combination with the first aspect, in some possible implementations, constructing the index field of the preset database based on the field name and field type of the subtable and the main field of the preset database includes: Based on the field name and field type of the subtable and the main field of the preset database, construct a mapping statement of the preset database; The index field is determined based on the mapping statement and the index name of the preset database.
[0008] In combination with the first aspect, in some possible implementations, constructing a mapping statement of the preset database based on the field name and field type of the subtable and the main field of the preset database includes: Based on the primary fields of the preset database, construct an initial mapping statement of the preset database; Performing data conversion on the field name and the field type of the subtable to obtain a converted field name and a converted field type; Based on the converted field name and the converted field type, the initial mapping statement is updated to obtain a mapping statement of the preset database.
[0009] In combination with the first aspect, in some possible implementations, synchronizing the change information to the preset database based on the index field of the preset database includes: Based on the change information, determining a candidate primary table that has been changed and a primary key value of the candidate primary table; Based on the primary key value, determining a subtable of the main table; Performing data type conversion on the main table and the sub-table to obtain a converted character string; The converted character string is saved in the index field of the preset database.
[0010] In combination with the first aspect above, in some possible implementations, after saving the converted character string to the index field of the preset database, the method further includes: In response to obtaining data exception information, obtaining identification information of the main table; wherein the data exception information is used to indicate that the converted character string is abnormally saved; The identification information is saved to the exception table of the MySql data; The exception table is polled to save the information to the index field of the preset database.
[0011] In combination with the first aspect above, in some possible implementations, the method further includes: Obtain the number of occurrences of the data anomaly information; If the occurrence frequency is greater than or equal to a preset frequency threshold, an alarm message is generated and output.
[0012] In a second aspect, a device for synchronizing MySql data to a database is provided, the device comprising: A determination module is used to determine the configuration information of the main table and sub-table of the relational database management system MySql data; A creation module, used to create index fields of a preset database based on the configuration information of the main table and the sub-table; A monitoring module, used for monitoring the change information of the main table and the sub-table; A synchronization module is used to synchronize the change information to the preset database based on the index field of the preset database.
[0013] In a third aspect, an electronic device is provided, comprising: a memory for storing executable program code; and a processor for calling and running the executable program code from the memory, so that the device-oriented network security protection device executes the method in the above-mentioned first aspect or any possible implementation of the first aspect.
[0014] In a fourth aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the method in the first aspect or any possible implementation of the first aspect.
[0015] In a fifth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0016] The present invention has the following beneficial effects: after obtaining the configuration information of the main table and the sub-table of MySql data, the index field of the preset database is created through the configuration information of the main table and the sub-table, so that the index field of the preset database can be automatically created and updated through the configuration information of the main table and the sub-table. Afterwards, the change information of the main table and the sub-table is monitored, and based on the index field of the preset database, the change information is synchronized to the preset database. In this way, by automatically creating the index field of the preset database, the change information is automatically synchronized to the preset database, thereby improving the accuracy of data synchronization and reducing the system maintenance cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 It is a schematic diagram of an implementation flow of a method for synchronizing MySql data to a database provided by an embodiment of the present invention; Figure 2 It is another implementation flow diagram of a method for synchronizing MySql data to a database provided by an embodiment of the present invention; Figure 3 It is another implementation flow diagram of a method for synchronizing MySql data to a database provided by an embodiment of the present invention; Figure 4 It is a schematic diagram of an implementation framework of a method for synchronizing MySql data to a database provided by an embodiment of the present invention; Figure 5 It is a schematic diagram of the composition structure of a device for synchronizing MySql data to a database provided by an embodiment of the present invention; Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0019] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of a method for synchronizing MySql data to a database according to the present invention, its specific implementation, structure, features and effects, in conjunction with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.
[0020] Among them, in the description of the embodiments of the present invention, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a way to describe the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present invention, "multiple" refers to two or more than two.
[0021] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0022] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
[0023] The following is a detailed description of a method for synchronizing MySql data to a database provided by the present invention in conjunction with the accompanying drawings. Figure 1 , which shows a flow chart of a method for synchronizing MySql data to a database provided by an embodiment of the present invention, the method comprising: 101. Determine configuration information of a main table and a sub-table of MySql data in a relational database management system.
[0024] Here, by determining the name information and business primary key of the main table and sub-table of the MySql data; and based on the name information and the business primary key, determining the configuration information of the main table and its sub-table. In some possible implementations, the configuration information of the main table and sub-table of the MySql data can be determined by the data synchronization system. The data synchronization system automatically creates or updates the ES containing nested type indexes corresponding to the main and sub-tables of the MySql database according to the initialized configuration information. For example: configure the main table t_user and its sub-tables t_user_education and t_user_address of the MySql database db_test in the data synchronization system. The data synchronization system queries the table fields and field types of the three tables in the db_test database according to the db_test database address and account information maintained in advance, and generates corresponding ES indexes containing nested types according to the configured master-sub-relationship. The functions of the data synchronization system include: automatically creating and updating the ES index containing nested types corresponding to the MySql master and sub-tables; receiving the change information of the MySql database master and sub-tables sent by the Canal client, and recording it as the change of the only record in the master table; querying the master and sub-table record information marked as changed, and converting it into a data structure that conforms to the ES index containing nested types, saving it to the corresponding ES index, and performing abnormal retries and abnormal notifications, etc. The configuration information is shown in Table 1: Table 1 Configuration information of the main table and sub-table of MySql data Among them, t_user is the main table, the table name is the real table name (name information of the main table), the business primary key field is the business primary key id of the main table, t_user_address; t_user_education and t_user_address are sub-tables, the table name needs to be concatenated with the name of the main table, separated by the separator "." (which can both identify the current table name and record the name of the main table), the business primary key field is the user_id of the sub-table, that is, the business primary key id of the corresponding main table t_user; "ES index name" is the index name of the synchronization data of the main table and its sub-tables. In this way, through the name information and business primary key of the main table and sub-table of MySql data, the configuration information of the main table and its sub-tables can be automatically created, thereby improving the efficiency of setting configuration information.
[0025] 102. Create an index field of a preset database based on the configuration information of the main table and the sub-table.
[0026] Here, in the configuration information of the main table and the sub-table, the field names and field types of the main table and the sub-table are searched, and the fields of the preset database are set by the address and account information of the preset database, so that the index fields of the preset database can be constructed. Among them, the preset database queries the database, for example, the preset database is an ES database.
[0027] In some possible implementations, the above step 102 can be performed by Figure 2 The steps shown achieve: 201, obtain the address and account information of the preset database.
[0028] Here, the data synchronization system automatically obtains the address and account information of the preset database, wherein the account information includes: data structure and data query account.
[0029] 202 : Based on the address and account information of the preset database, query the field names and field types of the main table and the sub-table in the configuration information of the main table and the sub-table.
[0030] Here, since the configuration information includes the field name and field type, the data synchronization system can obtain the field name and field type of the main table in the configuration information of the main table through the preset database address and account information; and the field name and field type of the sub-table can be obtained in the configuration information of the sub-table. Among them, the field type includes: integer type, decimal type, character type, and date type, etc. The data synchronization system automatically creates an ES index or updates the scheduled task of the index mapping field and polls every 5 seconds. Get the configured "ES index name". For example, es_user_data in Table 1.
[0031] 203. Determine the primary field of the preset database based on the field name and field type of the primary table.
[0032] Here, after the data synchronization system inquires about the field name and field type of the main table, it uses the field name and field type of the main table as the main field of the preset database to automatically construct the index field of the preset database.
[0033] 204 : construct an index field of the preset database based on the field name and field type of the subtable and the main field of the preset database.
[0034] Here, the index field of the preset database is obtained by converting the field name and field type of the subtable with the main field of the preset database. In this way, the index field of the preset database can be automatically constructed by combining the field name and field type of the main table and the subtable with the main field of the preset database, thereby facilitating data synchronization through the index field of the preset database.
[0035] In some possible implementations, the data synchronization system obtains all tables under the ES index name and distinguishes the main table and its sub-tables.
[0036] a) If the table name does not have a separator ".", the table is the main table, such as t_user in Table 1.
[0037] b) If the table name has a separator ".", the table is a subtable, and the name after the separator is the actual name of the subtable. For example, t_user_education and t_user_address in Table 1.
[0038] In some possible implementations, the above step 204 may be implemented by the following steps 241 and 242: 241. Construct a mapping statement of the preset database based on the field name and field type of the subtable and the main field of the preset database.
[0039] Here, the initial mapping statement of the preset database is constructed by the main field of the preset database; then, the field name of the sub-table and the field type are data converted to obtain the converted field name and the converted field type; finally, based on the converted field name and the converted field type, the initial mapping statement is updated to obtain the mapping statement of the preset database.
[0040] In some possible implementations, the data synchronization system queries the field name and field type of the main table based on the preset database address and account information as the main field of the ES index, and converts the field name and field type of the sub-table according to the rules to automatically build the ES index field, and converts through the main field to set the mapping statement.
[0041] The conversion rules are as follows: a) Integer type fields of the MySql main table, such as tinyint, int, bigint, etc., are mapped to keyword type fields of the ES index, and the field names remain unchanged.
[0042] b) Decimal fields in the MySql main table, such as double, float, and decimal, are mapped to double fields in the ES index, and the field names remain unchanged.
[0043] c) Character type fields of the MySql main table, such as varchar, text, longtext, etc., are mapped to keyword type fields of the ES index, and the field names remain unchanged.
[0044] d) The date type fields of the MySql main table, such as date, datetime, timestamp, etc., are mapped to the date type fields of the ES index, and the date format is set to "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss". The field name remains unchanged.
[0045] Finally, the data synchronization system queries the field name and field type of the MySql subtable as the nested field of the ES index, and adds them to the ES index field and mapping statement after conversion. The conversion rules are as follows: a) The table name of the MySql child table is used as the nested field name. The field type is set to "nested" nested type.
[0046] b) MySql sub-table fields are used as fields under the nested fields. The sub-table field mapping conversion rules refer to the main table mapping conversion rules: 1. The integer type fields of the MySql sub-table, such as tinyint, int, bigint, etc., are mapped to the keyword type fields under the ES index nested field (the name of the sub-table), and the field name remains unchanged.
[0047] 2. The decimal type fields of the MySql sub-table, such as double, float, decimal, etc., are mapped to the double type fields under the ES index nested fields (that is, the sub-table name), and the field name remains unchanged.
[0048] 3. Character type fields of the MySql subtable, such as varchar, text, longtext, etc., are mapped to keyword type fields under the ES index nested field (the name of the subtable), and the field name remains unchanged.
[0049] 4. The date type fields of the MySql subtable, such as date, datetime, timestamp, etc., are mapped to the date type fields under the ES index nested field (the name of the subtable), and the date format is set to "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss". The field name remains unchanged.
[0050] In some possible implementations, the currently constructed ES index fields and initial mapping statements are compared with the previous index fields and mapping statements to update the initial mapping statements and obtain the mapping statements of the preset database. The following process can be used to implement "updating the initial mapping statements based on the converted field names and the converted field types to obtain the mapping statements of the preset database": a) If the previous index field and mapping statement do not exist, create a new index.
[0051] b) If the index fields and mapping statements are different from the previous ones, update the index mapping fields.
[0052] c) If the index fields and mapping statements are the same as the previous one, no processing will be performed.
[0053] d) Save the latest index fields and mapping statements, so as to update the initial mapping statements and obtain the mapping statements of the preset database.
[0054] 242. Determine the index field based on the mapping statement and the index name of the preset database.
[0055] Here, the mapping statement and the index name of the preset database are combined as the index field of the preset database. In this way, by converting the mapping statement and the index name, the index field of the preset database can be constructed quickly and accurately.
[0056] 103. Monitor the change information of the main table and the sub-table.
[0057] Here, the data synchronization system records the change information of the MySql main table and its sub-tables, wherein the change information is data describing the change actions of the main table and its sub-tables.
[0058] First, when the data in the MySql main table t_user or its associated sub-tables t_user_education and t_user_address changes, the binlog log is monitored and parsed through Canal, and the parsed information is sent to the corresponding RabbitMQ switch.
[0059] Secondly, the RabbitMQ consumer of the data synchronization system receives messages from the bound queue and parses the binglog log message.
[0060] Again, according to the parsed binglog log message, the value of the business primary key field corresponding to the change table is obtained, so as to record the unique change data.
[0061] Here, if the change information of the binglog log message records the table t_user of the database db_test, the value of the table id field is obtained according to the "table name" and "business primary key field" of the initialized "library table configuration information". If the change information of the binglog log message records the table t_user_education or t_user_address of the database db_test, the value of the table field user_id is obtained according to the "table name" (the table name after the separator ".") and "business primary key field" of the initialized "library table configuration information".
[0062] Finally, the value corresponding to the "business primary key field" of the change table is saved to the Remote Dictionary Server (Redis) cache to record the change action (data changes in the main table and its sub-tables are recorded as a single change in the main table data).
[0063] Here, the key value saved in the cache = "MySql_to_es" + "database name" + "main table name". If the table that has changed is t_user, then the key value is "db_test.t_user" (i.e., the change information); if the table that has changed is t_user_education or t_user_address (the main table name can be found according to the initialized "library table configuration information"), then the key value is still "db_test.t_user". The value saved in the cache is a set. Add the value corresponding to the "business primary key field" to the set collection.
[0064] 104. Synchronize the change information to the preset database based on the index field of the preset database.
[0065] Here, through the change information, the candidate main table that has changed and the primary key value of the main table are analyzed, and the data types of the main table and its sub-tables are converted to obtain the index field of the preset database. In this way, through the configuration information of the main table and the sub-table, the index field of the preset database can be automatically created. After that, the change information of the main table and the sub-table is monitored, and based on the index field of the preset database, the change information is synchronized to the preset database. In this way, by automatically creating the index field of the preset database, the change information is automatically synchronized to the preset database, thereby improving the accuracy of data synchronization and reducing the system maintenance cost.
[0066] In some possible implementations, the above step 104 can be performed by Figure 3 The steps shown achieve: 301. Determine a candidate primary table that has been changed and a primary key value of the candidate primary table based on the change information.
[0067] Here, the main table where the change action occurs is analyzed from the change information of the main table and the sub-table, that is, the candidate main table is obtained, and the primary key value of the candidate main table (that is, the primary key id of the candidate main table) is further obtained.
[0068] 302. Determine a sub-table of the main table based on the primary key value.
[0069] Here, the scheduled task of the data synchronization system fuzzily queries the data with the prefix "MySql_to_es" in the Redis cache every 30 seconds, so as to obtain the main table and its primary key id that have changed in the MySql database db_test. After the data is queried, the data in the Redis cache is cleared. After that, the key value is parsed (key value = "MySql_to_es" + "database name" + "main table name"), and the "main table name" is obtained according to the key value. According to the "library table configuration information", all the "sub-table names" corresponding to the main table are obtained, so as to obtain a set of main and sub-tables, that is, the candidate main table and candidate word table are obtained.
[0070] 303: Perform data type conversion on the main table and the sub-table to obtain a converted character string.
[0071] Here, the value corresponding to the key value is parsed to obtain the set of primary key IDs of the master table of the group of master and sub-tables. The data synchronization system queries the master table based on the primary key ID of the master table and obtains the map of the return value of the master table.<String,Object> . And query its subtable according to the primary key id of the main table to obtain the return value of the subtable. Then use the subtable name as the key and the subtable return value as the value, and add the key-value to the map of the main table. Convert the date type field into a "yyyy-MM-dd" or "yyyy-MM-dd HH:mm:ss" formatted string to obtain the converted string.
[0072] 304, saving the converted character string to the index field of the preset database.
[0073] Here, after obtaining the converted string, the converted string is saved to the preset database according to the index field of the preset database to achieve data synchronization. In this way, by converting the data types of the main table and its sub-tables, the converted string is saved to the index field of the preset database, thereby achieving synchronization of MySql data to the preset database. Figure 4 As shown, the log parsing tool (Canal) monitoring module 402 monitors the change information in the MySql data 401. After that, the change information is filtered and sent to the MQ queue 403. The data synchronization system 404 obtains the main table id that has changed from the (Message Queue) MQ queue 403 and stores the main table id in the Redis database 405. The data synchronization system 404 obtains the work item id from the Redis database 405 every N minutes, where N is a number greater than 0. Finally, data is constructed according to the main table id and saved synchronously to the ES database 406.
[0074] 305. In response to obtaining the data anomaly information, obtain identification information of the main table.
[0075] The data exception information is used to characterize the abnormality of saving the converted string. The data exception information includes: abnormalities caused by non-system problems such as network, for example, abnormalities that occur during the process of saving the converted string to the index field of the preset database. The identification information of the main table is the primary key id and key value of the main table, where the key value = "MySql_to_es" + "database name" + "main table name".
[0076] 306, save the identification information to the exception table of the MySql data.
[0077] Here, the primary key id value and key value (key value = "MySql_to_es" + "database name" + "main table name") of the main table are saved to the exception table of the MySql data, where the exception table is used to store the identification information of the main table where the exception occurs during the data synchronization process.
[0078] 307 , polling the exception table to save it into the index field of the preset database.
[0079] Here, after the primary key id and key value of the main table where the exception occurs are saved to the exception table, the data synchronization system starts a new scheduled task to poll the data in the exception table, and when the data in the exception table is found, the above steps 301 to 307 are repeated. In this way, for the data where the exception occurs during the data synchronization process, by saving the identification information of the main table where the exception occurs to the exception table, and then retrying the main table where the exception occurs through the data synchronization system, the accuracy of data synchronization can be improved.
[0080] In some possible implementations, after the main table where the exception occurs is retried, the number of occurrences of the data exception information is counted; if the number of occurrences is greater than or equal to a preset number threshold, an alarm message is generated and output. The number of occurrences of the data exception information is the number of synchronization retries for the main table where the exception occurs. When the number of synchronization retries for the main table where the exception occurs reaches an upper limit (that is, the number of occurrences is greater than or equal to a preset number threshold, where the preset number threshold can be a custom setting, for example, the preset number threshold is 5), an alarm message is output, for example, the alarm message is output to the technical person in charge in the form of a text message or email, so that the technical person in charge can handle the main table where the exception occurs in a timely manner.
[0081] In an embodiment of the present invention, MySql data is synchronized to the ES database containing a nested type of index, and the "master-child" relationship of the data is still retained. The data can be queried or aggregated according to the nested fields, which greatly enhances the flexibility of ES search. The data synchronization system automatically creates and updates the index mapping field information, and automatically assembles it into a data structure that conforms to the ES containing nested type indexes, greatly reducing access and maintenance costs. The data synchronization system greatly reduces the update frequency of the ES index during the data synchronization process, and ensures orderly data updates, improving system stability and data accuracy.
[0082] The embodiment of the present invention provides a device for synchronizing MySql data to a database, such as Figure 5 As shown, the device 500 includes: Determination module 501, used to determine the configuration information of the main table and sub-table of the relational database management system MySql data; A creation module 502, used to create an index field of a preset database based on the configuration information of the main table and the sub-table; A monitoring module 503, used for monitoring the change information of the main table and the sub-table; The synchronization module 504 is used to synchronize the change information to the preset database based on the index field of the preset database.
[0083] In some possible implementations, the determination module 501 is further used to determine the name information and business primary key of the main table and sub-table of the MySql data; and determine the configuration information of the main table and sub-table based on the name information and the business primary key.
[0084] In some possible implementations, the creation module 502 is also used to obtain the address and account information of the preset database; based on the address and account information of the preset database, query the field names and field types of the main table and the sub-table in the configuration information of the main table and the sub-table; based on the field name and field type of the main table, determine the main field of the preset database; based on the field name, field type of the sub-table and the main field of the preset database, construct the index field of the preset database.
[0085] In some possible implementations, the creation module 502 is further used to construct a mapping statement of the preset database based on the field name, field type and main field of the preset database of the sub-table; and determine the index field based on the mapping statement and the index name of the preset database.
[0086] In some possible implementations, the creation module 502 is also used to construct an initial mapping statement of the preset database based on the main field of the preset database; perform data conversion on the field name and the field type of the sub-table to obtain a converted field name and a converted field type; based on the converted field name and the converted field type, update the initial mapping statement to obtain a mapping statement of the preset database.
[0087] In some possible implementations, the synchronization module 504 is further used to determine the candidate main table that has changed and the primary key value of the candidate main table based on the change information; determine the sub-table of the main table based on the primary key value; perform data type conversion on the main table and the sub-table to obtain a converted string; and save the converted string to the index field of the preset database.
[0088] In some possible implementations, the synchronization module 504 is also used to obtain identification information of the main table in response to obtaining data exception information; wherein the data exception information is used to characterize the abnormality of saving the converted string; save the identification information to an exception table of MySql data; and poll the exception table to save it to the index field of the preset database.
[0089] In some possible implementations, the synchronization module 504 is further used to obtain the number of occurrences of the data anomaly information; if the number of occurrences is greater than or equal to a preset number threshold, generate and output alarm information.
[0090] Optionally, the transmission medium can be a wired link (such as but not limited to coaxial cable, optical fiber and digital subscriber line (DSL)) or a wireless link (such as but not limited to wireless Fidelity (WIFI), Bluetooth and mobile device network).
[0091] It should be noted that: the device provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the computer device is divided into different functional modules to complete all or part of the functions described above. In addition, the shopping guide device provided in the above embodiment and the image extension method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0092] Figure 6 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. Figure 6As shown, the electronic device 600 includes: a memory 601, a processor 602, and a computer program 603 stored in the memory 601 and running on the processor 602, wherein when the processor 602 executes the computer program 603, the device can execute any of the aforementioned methods for synchronizing MySql data to a database. In addition, an embodiment of the present invention also protects a device, which may include a memory and a processor, wherein an executable program code is stored in the memory, and the processor is used to call and execute the executable program code to execute a method for synchronizing MySql data to a database provided by an embodiment of the present invention.
[0093] This embodiment can divide the functional modules of the device according to the above method example. For example, it can correspond to each functional module, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation. In the case of dividing each module corresponding to each function, the device may also include a signal uploading module, a determination module, an adjustment module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here.
[0094] It should be understood that the device provided in this embodiment is used to execute the above-mentioned method of synchronizing MySql data to a database, so the same effect as the above-mentioned implementation method can be achieved. In the case of an integrated unit, the device may include a processing module and a storage module. Among them, when the device is applied to a device, the processing module can be used to control and manage the actions of the device. The storage module can be used to support the device to execute mutual program codes, etc. Among them, the processing module can be a processor or a controller, which can implement or execute various exemplary logical boxes, modules and circuits described in conjunction with the disclosure of the present invention. The processor can also be a combination that implements a computing function, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc., and the storage module can be a memory.
[0095] In addition, the device provided in the embodiment of the present invention may be a chip, a component or a module, and the chip may include a connected processor and a memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip may execute a method for synchronizing MySql data to a database provided in the above embodiment. This embodiment also provides a computer-readable storage medium, in which a computer program code is stored, and when the computer program code is run on a computer, the computer executes the above-mentioned related method steps to implement a method for synchronizing MySql data to a database provided in the above embodiment.
[0096] This embodiment also provides a computer program product. When the computer program product is run on a computer, the computer executes the above-mentioned related steps to implement a method for synchronizing MySql data to a database provided in the above embodiment. Among them, the device, computer-readable storage medium, computer program product or chip provided in this embodiment are all used to execute the corresponding method provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding method provided above, and will not be repeated here. Through the description of the above implementation mode, the technicians in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In practical applications, the above-mentioned function allocation can be completed by different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In the embodiments provided by the present invention, it should be understood that the disclosed device and method can be implemented in other ways. For example, the device embodiment described above is only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, which may be electrical, mechanical or other forms.
[0097] It should be noted that the sequence of the above-mentioned embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The process depicted in the accompanying drawings does not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multi-tasking and parallel processing are also possible or may be advantageous. The various embodiments in this specification are described in a progressive manner, and the same and similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments. The above content is only a specific implementation method of the present invention, but the protection scope of the present invention is not limited to this. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be covered within the protection scope of the present invention.
Claims
1. A method for synchronizing MySql data to a database, characterized in that: The method comprises: Determine the configuration information of the main table and sub-table of the relational database management system MySql data; Based on the configuration information of the main table and the sub-table, create an index field of a preset database; Monitor the change information of the main table and the sub-table; Based on the index field of the preset database, the change information is synchronized to the preset database.
2. The method for synchronizing MySql data to a database according to claim 1, characterized in that: The configuration information of the main table and sub-table of the MySql data is determined, including: Determine the name information and business primary key of the main table and subtable of the MySql data; Based on the name information and the business primary key, configuration information of the main table and the sub-table is determined.
3. The method for synchronizing MySql data to a database according to claim 1, characterized in that: The step of creating an index field of a preset database based on the configuration information of the main table and the sub-table includes: Get the address and account information of the preset database; Based on the address and account information of the preset database, query the field names and field types of the main table and the sub-table in the configuration information of the main table and the sub-table; Determine the primary field of the preset database based on the field name and field type of the primary table; Based on the field name and field type of the sub-table and the main field of the preset database, an index field of the preset database is constructed.
4. The method for synchronizing MySql data to a database according to claim 3, characterized in that: The step of constructing the index field of the preset database based on the field name and field type of the sub-table and the main field of the preset database includes: Based on the field name and field type of the subtable and the main field of the preset database, construct a mapping statement of the preset database; The index field is determined based on the mapping statement and the index name of the preset database.
5. The method for synchronizing MySql data to a database according to claim 4, characterized in that: The step of constructing a mapping statement of the preset database based on the field name and field type of the subtable and the main field of the preset database includes: Based on the primary fields of the preset database, construct an initial mapping statement of the preset database; Performing data conversion on the field name and the field type of the subtable to obtain a converted field name and a converted field type; Based on the converted field name and the converted field type, the initial mapping statement is updated to obtain a mapping statement of the preset database.
6. The method for synchronizing MySql data to a database according to claim 1, characterized in that: The step of synchronizing the change information to the preset database based on the index field of the preset database includes: Based on the change information, determining a candidate primary table that has been changed and a primary key value of the candidate primary table; Based on the primary key value, determining a subtable of the main table; Performing data type conversion on the main table and the sub-table to obtain a converted character string; The converted character string is saved in the index field of the preset database.
7. The method for synchronizing MySql data to a database according to claim 6, characterized in that: After saving the converted character string to the index field of the preset database, the method further includes: In response to obtaining data exception information, obtaining identification information of the main table; wherein the data exception information is used to indicate that the converted character string is abnormally saved; The identification information is saved to the exception table of the MySql data; The exception table is polled to save the information to the index field of the preset database.
8. The method for synchronizing MySql data to a database according to claim 7, characterized in that: The method further comprises: Obtain the number of occurrences of the data anomaly information; If the occurrence frequency is greater than or equal to a preset frequency threshold, an alarm message is generated and output.
9. A device for synchronizing MySql data to a database, characterized in that: The device comprises: A determination module is used to determine the configuration information of the main table and sub-table of the relational database management system MySql data; A creation module, used to create index fields of a preset database based on the configuration information of the main table and the sub-table; A monitoring module, used for monitoring the change information of the main table and the sub-table; A synchronization module is used to synchronize the change information to the preset database based on the index field of the preset database.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed, the method according to any one of claims 1 to 8 is implemented.