A method for automatically initializing database SQL

By automatically initializing database SQL, the startup stamp and storage area are used to optimize database configuration and script execution, solving the problem of slow database response caused by repeated startup projects or incremental projects, achieving efficient use of database resources and improving project startup quality. .

CN118409904BActive Publication Date: 2024-09-06北京科杰科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410866266.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-09-06
Estimated Expiration
2044-07-01

AI Technical Summary

Technical Problem

In the existing technology, repeatedly started projects or incremental projects based on a certain project cannot be read quickly, resulting in slow database response and resource waste.

Method used

Adopt the method of automatically initializing database SQL, by setting startup stamps and allocating startup memory, recording the number of startups and status of the project, determining the parsing path and configuration file based on the number of startups and status, optimizing database configuration and script execution, and using storage area allocation to quickly The parts that are called and the parts that change less ensure efficient use of database resources.

Benefits of technology

It effectively improves the usability of the database and the speed of data calling, saves database startup resources, avoids operation failures caused by project changes, ensures the quality of project startup, and reduces the waste of database startup resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409904B
    Figure CN118409904B
Patent Text Reader

Abstract

The present invention relates to the technical field of databases, and in particular to a method for automatically initializing a database SQL, comprising: setting a startup stamp and allocating a startup memory of the startup stamp; selecting a corresponding configuration file according to the startup memory to configure the database; parsing the database configuration and determining a parsing path according to the number of startups; executing a project according to the database configuration; confirming an execution state, and recording the execution state in a startup memory corresponding to the project in the startup stamp; recording the number of runs and the running state of the project by setting the startup stamp, reading the running state when the corresponding project runs next time, and configuring the database accordingly according to the reading, thereby effectively improving the usability of the database and effectively reducing the resources to be called for reading the database, thereby effectively saving the startup resources of the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of databases, and in particular to a method for automatically initializing database SQL. Background Art

[0002] Since the system involves many service modules, each service has its own independent database, and the system needs to initialize data into the database table in advance when it is deployed. The current practice is to manually import the database SQL script into the database. This method is labor-intensive and easy to miss the SQL initialization script. The subsequent maintenance cost is also high. For example, if a field in the database table is modified or added, it will cause certain difficulties for service deployment.

[0003] After the project is deployed in different environments, the database initialization script needs to be manually maintained at a high cost. Under normal circumstances, the database initialization SQL needs to be manually executed one by one, which is time-consuming and labor-intensive.

[0004] China Patent Authorization Announcement No.: CN116909884B discloses a database fuzz testing method for configuration defects, the purpose of which is to solve the problem of low configuration code coverage of current testing methods. The technical solution is: construct a database fuzz testing system for configuration defects consisting of a configuration taint analysis module, a configuration plugging module, and a database fuzz testing module; the configuration taint analysis module obtains the impact range of the target configuration and the configuration and program basic block mapping relationship set; the configuration plugging module reads the source code of the software to be tested and the configuration and program basic block mapping relationship set to plug the software source code; the database fuzz testing module performs coverage-guided gray box fuzz testing on the plugged software, and uses a configuration-oriented two-stage mutation strategy to penetrate the configuration control branch conditions for the seeds that execute the configuration code, and outputs a configuration defect set. The invention can fully test the configuration code in the tested software, improve the coverage, and effectively detect configuration defects in the database software.

[0005] However, the above method has the following problems: the project that is repeatedly started or the incremental project added based on a certain project cannot be read quickly, resulting in slow response of the database. Summary of the invention

[0006] To this end, the present invention provides a method for automatically initializing database SQL to overcome the problem in the prior art that repeatedly started projects or incremental projects added based on a certain project cannot be quickly read, resulting in slow database response and thus wasting database startup resources.

[0007] To achieve the above object, the present invention provides a method for automatically initializing database SQL, comprising:

[0008] Set the startup stamp and allocate the startup memory of the startup stamp;

[0009] When the project is started, the start stamp responds to the start of the project and places the content of the project into the project memory corresponding to the project;

[0010] When the project is running, the project determines the parameter information of the project according to the startup memory of the startup stamp;

[0011] When closing a project, the startup stamp retains the project memory and records the number of startups of the corresponding project;

[0012] Selecting a corresponding configuration file according to the startup memory to configure the database;

[0013] Parsing the database configuration and determining a parsing path according to the startup times;

[0014] For a single project, if the startup times are stored in the project memory, the database sets the parsing path to the configuration file;

[0015] If the startup times are not stored in the project memory, the database sets the parsing path to the default configuration file;

[0016] For items with changes, the database sets the parsing path to the incremental change file;

[0017] Execute the project according to the database configuration;

[0018] Confirming the execution status, and recording the execution status in the startup memory corresponding to the item in the startup stamp;

[0019] The startup stamp runs independently outside the database and is provided with a corresponding startup quantity extreme value. When the startup times of any project reaches the startup quantity extreme value, the startup stamp deletes the corresponding project.

[0020] Furthermore, when setting the start stamp, it includes:

[0021] Setting a number of storage areas according to the usage frequency of the database;

[0022] Wherein, the storage area at least includes a counter set in a read-only storage area and an archive set in a temporary storage area;

[0023] When the start stamp responds, the start behavior of the corresponding project is recorded in the storage area, and the number of starts of the corresponding project is accumulated;

[0024] When the project is not started for the first time, the storage area changes the counter;

[0025] When the project is started for the first time, the start stamp sets a counter corresponding to the corresponding project in the storage area;

[0026] For a single item, said archive is associated with a record of said counter;

[0027] When the counter reaches a storage threshold, the start stamp records the corresponding item as a new item.

[0028] Furthermore, when configuring the database using the configuration file, it includes:

[0029] Reading the startup memory of the startup stamp;

[0030] Obtaining the archive of the startup memory, and determining the configuration directory of the database according to the archive;

[0031] Configure the database;

[0032] Among them, for a single database, it corresponds to a single archive in the startup memory. When the database changes, the corresponding archive changes accordingly.

[0033] Furthermore, when the parsing path is the configuration file, the database is set according to the startup stamp, and a corresponding archive is read to configure the database.

[0034] Furthermore, when the parsing path is the default configuration file, the database is set according to the initialized database file.

[0035] Further, when reading the incremental change file, the database updates the script file based on the file in the startup memory;

[0036] Wherein, for any project, if the startup memory contains part of the content of the corresponding project, the database loads the corresponding update script file based on the archive in the startup memory, and,

[0037] The corresponding items are recorded as new items.

[0038] Furthermore, if the update script file of the project can be executed, the startup stamp records the configuration file of the corresponding project in the startup memory;

[0039] Wherein, if the configuration file of any project in the startup memory is the same as the configuration file of the project, the startup stamp associates the corresponding project with the project in the startup memory;

[0040] The configuration file includes an update script file.

[0041] Further, when the startup stamp responds, if the corresponding database cannot run the corresponding project, the startup stamp sets the archive corresponding to the corresponding project as a bad archive;

[0042] When the startup stamp reaches the startup quantity extreme value, the counter and archive corresponding to the bad file are deleted respectively.

[0043] Furthermore, when confirming the execution status of the project, the project is recorded separately according to whether the corresponding project is successful, including:

[0044] The operation is successful, partially successful, or failed, and the record results are written into the corresponding counters.

[0045] Furthermore, when deleting a project, the startup stamp deletes the counter of the corresponding project for the project that can be run;

[0046] If any archive does not have a corresponding counter, the startup stamp deletes the archive.

[0047] Compared with the prior art, the beneficial effect of the present invention lies in that, by setting a startup stamp, the number of times a project is run and the running status are recorded, and the corresponding project is read when it is run next time, and the database is configured accordingly based on the reading, which effectively improves the usability of the database and effectively reduces the resources required to read the database, thereby effectively saving the startup resources of the database.

[0048] Furthermore, by storing the startup stamps separately according to their storage contents, the parts that need to be quickly called are placed in a temporary storage area, and the parts that change less are placed in a read-only storage area, which effectively improves the data calling speed and further saves the startup resources of the database.

[0049] Furthermore, by setting up the database archive, corresponding settings are made for changes in the database, and the corresponding archive of the database is read the next time the database is started, which effectively improves the timeliness of database archive reading and further saves database startup resources.

[0050] Furthermore, the project to which the new script is added is recorded as a new project, which effectively avoids the failure of database operation due to project changes and improves the operation quality of the project, thereby further saving database startup resources.

[0051] Furthermore, by recording the number of record items, data anomalies caused by memory overflow can be avoided, which not only ensures the quality of project startup, but also further saves database startup resources.

[0052] This application also solves the problem of high cost of manual maintenance of database initialization scripts after the project is deployed in different environments. Under normal circumstances, database initialization SQL requires manual execution of initialization scripts one by one, because the labor cost is relatively high and certain problems may be caused by missed scripts. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 A flowchart of a method for automatically initializing database SQL according to the present invention;

[0054] Figure 2 A flowchart for allocating startup memory for an embodiment of the present invention;

[0055] Figure 3 This is a record accumulation flow chart of an embodiment of the present invention;

[0056] Figure 4 A schematic diagram of the project startup logic for an embodiment of the present invention. DETAILED DESCRIPTION

[0057] In order to make the objects and advantages of the present invention more clearly understood, the present invention is further described below in conjunction with embodiments; it should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.

[0058] The preferred embodiments of the present invention are described below with reference to the accompanying drawings. It should be understood by those skilled in the art that these embodiments are only used to explain the technical principles of the present invention and are not intended to limit the protection scope of the present invention.

[0059] It should be noted that, in the description of the present invention, terms such as "up", "down", "left", "right", "inside" and "outside" indicating directions or positional relationships are based on the directions or positional relationships shown in the drawings. This is merely for the convenience of description and does not indicate or imply that the device or element must have a specific orientation, be constructed and operated in a specific orientation. Therefore, it cannot be understood as a limitation on the present invention.

[0060] In addition, it should be noted that in the description of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0061] See also Figure 1As shown, it is a flow chart of a method for automatically initializing database SQL according to the present invention, based on a method for automatically initializing database SQL, including:

[0062] Step S1, setting a startup stamp and allocating a startup memory of the startup stamp;

[0063] Step S2, selecting a corresponding configuration file from the startup memory to configure the database;

[0064] Step S3, parsing the database configuration and determining the parsing path according to the number of startup times;

[0065] Step S4, executing the project according to the database configuration;

[0066] Step S5, confirming the execution status, and recording the execution status in the startup memory corresponding to the item in the startup stamp;

[0067] Among them, the startup stamp runs independently outside the database and has a corresponding startup quantity extreme value. When the startup times of any project reaches the startup quantity extreme value, the startup stamp will delete the corresponding project.

[0068] See also Figure 2 As shown, it is a flow chart of allocating startup memory according to an embodiment of the present invention, wherein step S1 includes:

[0069] Step S11, when starting a project, the start stamp responds to the start of the project and places the content of the project into the project memory corresponding to the project;

[0070] Step S12, when the project is running, the project determines the parameter information of the project according to the startup memory of the startup stamp;

[0071] Step S13, when closing a project, the startup stamp retains the project memory and records the number of startups of the corresponding project;

[0072] The specific method for determining the parsing path is:

[0073] For a single project, if the number of startup times is stored in the project memory, the database will set the parsing path to the configuration file;

[0074] If there is no startup count in the project memory, the database will set the parsing path to the default configuration file;

[0075] For items with changes, the database sets the parsing path to the incremental change file;

[0076] By setting the startup stamp, the number of times the project is run and the running status are recorded, and the data is read when the corresponding project is run next time. The database is configured accordingly based on the reading. This effectively improves the ease of use of the database and effectively reduces the resources required to read the database, thereby effectively saving database startup resources.

[0077] Specifically, when setting the start stamp, it includes:

[0078] Set up several storage areas according to the frequency of database use;

[0079] Wherein, the storage area includes at least a counter set in a read-only storage area and an archive set in a temporary storage area;

[0080] When the stamp response is initiated, the startup behavior of the corresponding project is recorded in the storage area, and the startup times of the corresponding project are accumulated;

[0081] When the counter reaches the storage threshold, the start stamp records the corresponding item as a new item.

[0082] See also Figure 3 As shown, it is a record accumulation flow chart of an embodiment of the present invention:

[0083] The record accumulation process includes

[0084] Step S131, when the project is not started for the first time, the storage area changes the counter;

[0085] Step S132, when the project is started for the first time, the startup stamp sets a counter corresponding to the corresponding project in the storage area;

[0086] Among them, for a single item, archiving is related to the recording of counters;

[0087] By storing the startup stamp separately according to its storage content, the part that needs to be called quickly is placed in the temporary storage area, and the part that changes less is kept in the read-only storage area. This effectively improves the data calling speed and further saves the startup resources of the database.

[0088] Specifically, when configuring the database using the configuration file, it includes:

[0089] Read the boot memory of the boot stamp;

[0090] Get the archive of the startup memory and determine the configuration directory of the database based on the archive;

[0091] Configure the database;

[0092] Among them, for a single database, it corresponds to a single archive in the startup memory. When the database changes, the corresponding archive changes accordingly.

[0093] Specifically, when the parsing path is a configuration file, the database sets the database according to the startup stamp and reads the corresponding archive to configure the database.

[0094] Specifically, when the parsing path is a default configuration file, the database is set according to the initialized database file.

[0095] By setting up database archives, corresponding settings are made for changes in the database, and the corresponding archives of the database are read the next time the database is started. This effectively improves the timeliness of database archive reading and further saves database startup resources.

[0096] Specifically, when reading the incremental change file, the database updates the script file based on the file in the startup memory;

[0097] Wherein, for any project, if the startup memory contains part of the content of the corresponding project, the database loads the corresponding update script file based on the archive in the startup memory, and,

[0098] The corresponding items are recorded as new items.

[0099] Specifically, if the update script file of the project can be executed, the startup stamp will record the configuration file of the corresponding project in the startup memory;

[0100] Among them, if the configuration file of any project in the startup memory is the same as the configuration file of the project, the startup stamp will associate the corresponding project with the project in the startup memory;

[0101] The configuration files include the update script files.

[0102] Projects that add new scripts are recorded as new projects, which effectively avoids database operation failures due to project changes and improves the project operation quality, thereby further saving database startup resources.

[0103] Specifically, when the startup stamp responds, if the corresponding database cannot run the corresponding project, the startup stamp sets the archive corresponding to the corresponding project as a bad archive;

[0104] When the startup stamp reaches the startup quantity limit, the counter and archive corresponding to the bad file will be deleted respectively.

[0105] Specifically, when confirming the execution status of a project, the project is recorded separately according to whether the corresponding project is successful, including:

[0106] The operation is successful, partially successful, or failed, and the record results are written into the corresponding counters.

[0107] Specifically, when the startup stamp deletes a project, for a project that can be run, the startup stamp deletes the counter of the corresponding project;

[0108] If any archive does not have a corresponding counter, the startup stamp will delete the archive.

[0109] By recording the number of record items, data anomalies caused by memory overflow can be avoided, which not only ensures the quality of project startup, but also further saves database startup resources.

[0110] The above method of automatically initializing the database includes two parts: one is the initial SQL script for the database table and data, and the other is the SQL script for the incrementally changed database table and data. When the service is started for the first time, the program first connects to the database through the startup code (using JDBC), then queries the list of existing tables in the database and compares it with the tables in the predefined SQL script. If a table does not exist in the database, the program will create the corresponding database and table. Then, the program will execute the initialization script, write the preset data into the table, and complete the database initialization.

[0111] See also Figure 4 As shown, it is a logical schematic diagram of project startup according to an embodiment of the present invention.

[0112] When the project is first started, the system will write the data that needs to be initialized into the corresponding database table. After the initialization is completed, the project will start normally. Later, if the system needs to restart the service, the system will first check whether the database in the preset SQL script already exists. If it does, it means that the initialization script has been executed. The system will skip the execution step of the initialization SQL script and start the program directly. Then, the system will parse the incremental script change file and execute the SQL script in it. After executing the incremental script, the system will record these executed script files in the executed file directory and clear the incremental script change file. Finally, the system starts normally.

[0113] The implementation includes the following specific steps:

[0114] Step St1: The project implementer saves the SQL script file to be initialized and the incremental update SQL script file in the server directory in advance. The directory address can be created by customizing, and then fill the directory address into the default configuration file for project startup.

[0115] Step St2, after the address is configured, start the project. During the project startup process, the parameters in the default configuration file will be read to obtain the storage directory of the SQL script to be executed. After obtaining the directory, the SQL script file can be parsed through the program being started, the SQL language in it can be read, and the SQL language can be executed.

[0116] Specific parameters refer to the information used to configure the automatic initialization process, including but not limited to:

[0117] SQL script save directory: This refers to the directory path containing the initialization SQL script file. This directory stores the SQL scripts that the system needs to execute, such as creating tables, inserting data, etc.

[0118] Database connection information: includes the database address (IP address or domain name), port number, database name, login user name and password, etc., which are used by the program to connect to the database for operation.

[0119] These parameters are usually configured in the default configuration file of the project. During the project startup process, the program reads the default configuration file and obtains these parameter information from it. The method of identifying these parameters is usually to obtain the corresponding values ​​by reading specific fields or key values ​​of the configuration file. For example, you can use the property file reading method in Java (such as the Properties class) or the configuration file parsing library (such as yaml, json parser) to read the parameter information in the configuration file.

[0120] For a single database, its parameter information is called system variables in official documents, and different variables have different functions.

[0121] The MySQL server maintains many system variables that represent its configuration, all of which have default values. They can generally be set in the startup command line or in the configuration file.

[0122] System variables are divided into global system variables (global) and session system variables (session). Some variables have both global variables and session variables, and some variables have only global variables. Global variables affect the global operation of the server, and session variables only affect specific client connection-related operations. If a session variable is not set separately, it is inherited from the corresponding global variable.

[0123] When the MySQL service is started, it assigns values ​​to global variables according to the options specified in the configuration file or command line. If no options are specified, the default values ​​are used. After the service is started, you can dynamically change the values ​​of some global variables by connecting to the server and executing the SET GLOBAL var_name statement. To change global variables, you must have the SUPER privilege.

[0124] Once the program obtains these parameter information, it can parse the SQL script files and execute the SQL statements in the configured SQL script save directory, thereby realizing the automatic initialization process of the database.

[0125] Step St3, after the SQL script is executed, the project can be started successfully, which means that the SQL script is executed successfully, and the project can be started and run smoothly, which means that the SQL script is executed successfully, and the database structure and data have been initialized and set as expected. The success of the project startup is the final verification of the entire automatic initialization process, ensuring that the system can run normally after startup, and the structure and data status of the database are correct.

[0126] Step St4, after the SQL script is successfully executed, the execution result can be confirmed by printing a detailed update log.

[0127] These changelogs should include the following:

[0128] 1. Check the database and table: The log should record the checked database and table information to ensure that the database structure and table are created successfully.

[0129] 2. Data initialization status: record the insertion status of the initialization data, including the amount of data successfully inserted and possible errors or exceptions.

[0130] 3. Execution of incremental scripts: If an incremental script is executed, the log should record the execution status of each incremental script, including the executed SQL statements and execution results.

[0131] 4. Execution Status: Records the overall status of the script execution, such as success, partial success, or failure.

[0132] By printing these detailed update logs, project implementers can clearly understand the execution status and results of the automatic initialization process, so as to promptly discover and solve potential problems. The output of update logs can usually be achieved through the logging framework (SLF4J), ensuring that the log information can clearly show the details and status of the script execution.

[0133] So far, the technical solutions of the present invention have been described in conjunction with the preferred embodiments shown in the accompanying drawings. However, it is easy for those skilled in the art to understand that the protection scope of the present invention is obviously not limited to these specific embodiments. Without departing from the principle of the present invention, those skilled in the art can make equivalent changes or substitutions to the relevant technical features, and the technical solutions after these changes or substitutions will fall within the protection scope of the present invention.

[0134] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for automatically initializing database SQL, characterized in that: include: Set the startup stamp and allocate the startup memory of the startup stamp; When the project is started, the start stamp responds to the start of the project and places the content of the project into the project memory corresponding to the project; When the project is running, the project determines the parameter information of the project according to the startup memory of the startup stamp; When closing a project, the startup stamp retains the project memory and records the number of startups of the corresponding project; Selecting a corresponding configuration file according to the startup memory to configure the database; Parsing the database configuration and determining a parsing path according to the startup times; For a single project, if the startup times are stored in the project memory, the database sets the parsing path to the configuration file; If the startup times are not stored in the project memory, the database sets the parsing path to the default configuration file; For items with changes, the database sets the parsing path to the incremental change file; Execute the project according to the database configuration; Confirming the execution status, and recording the execution status in the startup memory corresponding to the item in the startup stamp; Wherein, the startup stamp runs independently outside the database and is provided with a corresponding startup quantity extreme value. When the startup times of any project reaches the startup quantity extreme value, the startup stamp deletes the corresponding project; When setting the start stamp, it includes: Setting a number of storage areas according to the usage frequency of the database; Wherein, the storage area at least includes a counter set in a read-only storage area and an archive set in a temporary storage area; When the start stamp responds, the start behavior of the corresponding project is recorded in the storage area, and the number of starts of the corresponding project is accumulated; When the project is not started for the first time, the storage area changes the counter; When the project is started for the first time, the start stamp sets a counter corresponding to the corresponding project in the storage area; For a single item, said archive is associated with a record of said counter; When the counter reaches a storage threshold, the start stamp records the corresponding item as a new item.

2. The method for automatically initializing database SQL according to claim 1, characterized in that: When the configuration file is used to configure the database, it includes: Reading the startup memory of the startup stamp; Obtaining the archive of the startup memory, and determining the configuration directory of the database according to the archive; Configure the database; Among them, for a single database, it corresponds to a single archive in the startup memory. When the database changes, the corresponding archive changes accordingly.

3. The method for automatically initializing database SQL according to claim 1, characterized in that: When the parsing path is the configuration file, the database is set according to the startup stamp and the corresponding archive is read to configure the database.

4. The method for automatically initializing database SQL according to claim 1, characterized in that: When the parsing path is the default configuration file, the database is set according to the initialized database file.

5. The method for automatically initializing database SQL according to any one of claims 1 or 3, characterized in that: When reading the incremental change file, the database updates the script file based on the file in the startup memory; Wherein, for any project, if the startup memory contains part of the content of the corresponding project, the database loads the corresponding update script file based on the archive in the startup memory, and, The corresponding items are recorded as new items.

6. The method for automatically initializing database SQL according to claim 5, characterized in that: If the update script file of the project can be executed, the startup stamp records the configuration file of the corresponding project in the startup memory; Wherein, if the configuration file of any project in the startup memory is the same as the configuration file of the project, the startup stamp associates the corresponding project with the project in the startup memory; The configuration file includes an update script file.

7. The method for automatically initializing database SQL according to any one of claims 3, 4 or 6, characterized in that: When the startup stamp responds, if the corresponding database cannot run the corresponding project, the startup stamp sets the archive corresponding to the corresponding project as a bad archive; When the startup stamp reaches the startup quantity extreme value, the counter and archive corresponding to the bad file are deleted respectively.

8. The method for automatically initializing database SQL according to claim 1, characterized in that: When confirming the execution status of a project, record the project separately based on whether the corresponding project is successful, including: The operation is successful, partially successful, or failed, and the record results are written into the corresponding counters.

9. The method for automatically initializing database SQL according to claim 7, characterized in that: When deleting a project, the startup stamp deletes the counter of the corresponding project for the project that can be run; If any archive does not have a corresponding counter, the startup stamp deletes the archive.