Database connectivity detection method, apparatus, device, and storage medium
By using an automated database connectivity testing method, which generates configuration files using pre-configured scripts and performs permission verification on the target database, the errors and inefficiencies caused by manual testing are solved, achieving efficient database connectivity testing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-07
- Publication Date
- 2026-03-31
AI Technical Summary
Existing technologies require manual intervention for database permission checks, which can lead to incorrect or missed permission requests, resulting in low efficiency and high costs.
The system generates configuration files by executing pre-configured scripts, extracts configuration information from the target database, and performs automated connectivity checks based on this information, including database-level, table-level, row-level, and column-level permission verification. The system then generates the test results and compares them with the expected results.
It enables rapid and automatic detection of target databases, avoiding errors and inefficiencies caused by manual detection, and improving detection efficiency and accuracy.
Smart Images

Figure CN115470128B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a database connectivity detection method, apparatus, device, and storage medium. Background Technology
[0002] Database testing primarily tests the database structure, tables, and data access relationships within a software system. Typically, a company's database is its most valuable asset; applications can be rewritten repeatedly, with older versions being discarded and new ones installed. Before a project is released, database access permissions are checked to ensure they are valid. However, current database access permission checks rely on manual requests, which are prone to errors and omissions, leading to post-release anomalies due to permission deficiencies. Manual testing is inefficient and costly due to the significant manpower required. Summary of the Invention
[0003] To address the aforementioned technical problems, embodiments of this application provide a database connectivity detection method, apparatus, device, and storage medium.
[0004] According to one aspect of the embodiments of this application, a database connectivity detection method is provided, comprising:
[0005] Execute the pre-configured script to generate the corresponding configuration file;
[0006] Extract the configuration information of the target database contained in the configuration file;
[0007] Based on the configuration information of the target database, a connectivity test is performed on the target database to obtain the corresponding test result.
[0008] If the detection result is consistent with the expected result, then the connectivity of the target database is determined to be normal.
[0009] According to one aspect of the embodiments of this application, a database connectivity detection apparatus is provided, comprising:
[0010] The execution module is used to execute pre-configured scripts to generate corresponding configuration files;
[0011] The extraction module is used to extract the configuration information of the target database contained in the configuration file;
[0012] The testing module is used to perform connectivity detection on the target database based on the configuration information of the target database, so as to obtain the detection result corresponding to the target database;
[0013] The judgment module is used to determine that the connectivity of the target database is normal if the detection result is consistent with the expected result.
[0014] According to one aspect of an embodiment of this application, the testing module specifically includes:
[0015] The determination submodule determines the items to be detected in the target database based on the configuration information of the target database;
[0016] The permission point verification submodule calls the corresponding detection function to perform permission point verification on the target database based on the item to be detected in the target database.
[0017] According to one aspect of an embodiment of this application, the permission point verification submodule further includes:
[0018] The determining unit is configured to determine the detection-level permissions of the target database based on the configuration information, wherein the detection-level permissions include at least one of database-level permissions, table-level permissions, row-level permissions, and column-level permissions;
[0019] The invocation unit is used to invoke the corresponding detection function to perform connectivity detection on the target database based on the detection level permission.
[0020] According to one aspect of an embodiment of this application, the calling limit unit is specifically used for:
[0021] Based on the detection level, determine the target permission point corresponding to the target database, and call the detection function corresponding to the target permission point;
[0022] Based on the detection function, a target permission point verification instruction is executed on the target database, and the corresponding execution result is written to a log file to determine the detection result corresponding to the target database based on the log file.
[0023] According to one aspect of an embodiment of this application, the apparatus further includes:
[0024] The connection execution module is used to execute database connection instructions to the target database using the account information and password information in the configuration file.
[0025] The connectivity determination module is used to determine whether the target database can be connected normally based on the response result of the target database;
[0026] The determination submodule is used to execute the step of determining the items to be detected in the target database based on the configuration information of the target database if the determination is yes.
[0027] According to one aspect of an embodiment of this application, the extraction module is further specifically used for:
[0028] The file format of the configuration file is determined to be a unified configuration format;
[0029] If the determination is yes, then extract the configuration information of the target database from the configuration file;
[0030] If the determination is negative, then the configuration information of the target database is extracted from the configuration file according to the configuration information extraction method corresponding to the file format of the configuration file.
[0031] According to one aspect of the embodiments of this application, the apparatus further includes an alarm module, the alarm module being specifically used for:
[0032] If the output data of the target database is inconsistent with the expected data, an alarm message is sent. The alarm message includes alarm details for the absence of the corresponding detection permission level.
[0033] Determine the new script parameters based on the alarm details;
[0034] Write the newly added script parameters into the preset script and re-execute the preset script.
[0035] According to one aspect of the embodiments of this application, an electronic device is provided, including: one or more processors; and a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the database connectivity detection method as described above.
[0036] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided, on which computer-readable instructions are stored, which, when executed by a computer's processor, cause the computer to perform the database connectivity detection method as described above.
[0037] According to one aspect of the embodiments of this application, a computer program product is also provided, including a computer program that, when executed by a processor, implements the steps in the database connectivity detection method as described above.
[0038] In the technical solution provided by the embodiments of this application, a pre-configured script is executed to generate a corresponding configuration file, and the configuration information of the target database in the configuration file is extracted. Then, based on the configuration information of the target database, connectivity detection is performed on the target database to obtain the corresponding detection result. The obtained detection result is compared with the expected result. If the detection result is consistent with the expected result, it indicates that the connectivity of the target database is normal. In this way, by automatically executing the pre-configured script, it is possible to quickly access the target database and perform the detection items in the configuration file, avoiding the omissions or low efficiency problems caused by manual application and manual detection.
[0039] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0040] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:
[0041] Figure 1 This is a schematic diagram of an implementation environment involved in an embodiment of this application;
[0042] Figure 2 This is a flowchart illustrating a database connectivity detection method in an exemplary embodiment of this application;
[0043] Figure 3 This is a schematic diagram illustrating the interaction between the client and the database, as shown in another exemplary embodiment of this application;
[0044] Figure 4 This is another exemplary illustration of the interaction between the client and the database in this application;
[0045] Figure 5 This is a flowchart illustrating a database connectivity detection method in another exemplary embodiment of this application;
[0046] Figure 6 yes Figure 2 The flowchart of step S220 in the illustrated embodiment is shown in an exemplary embodiment.
[0047] Figure 7 This is another exemplary embodiment of the present application illustrating the overall service flow diagram of database connectivity detection;
[0048] Figure 8 This is a flowchart illustrating the re-execution of a preset script, as shown in an exemplary embodiment of this application;
[0049] Figure 9 This is another exemplary embodiment of the present application illustrating the overall flowchart for implementing database connectivity detection;
[0050] Figure 10 This is a block diagram illustrating a database connectivity detection device according to an exemplary embodiment of this application;
[0051] Figure 11 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present application is shown. Detailed Implementation
[0052] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0053] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0054] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0055] In this application, "multiple" refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0056] A database is a repository for data. It has a large storage capacity, capable of holding millions, tens of millions, or even hundreds of millions of data entries. However, data is not stored arbitrarily; there are certain rules governing its storage, otherwise query efficiency would be very low. In the data-rich world of the internet, there is an abundance of data. A database is a computer software system that stores and manages data according to a data structure. The concept encompasses two aspects: First, a database is an entity, a "repository" that can reasonably store data. Users store transactional data that needs management in this "repository." The concepts of "data" and "repository" combine to form a database. Second, a database represents a new method and technology for data management. It can organize data more appropriately, maintain data more conveniently, control data more rigorously, and utilize data more effectively. In other words, as the most important foundational software, the database is the cornerstone ensuring the stable operation of computer systems.
[0057] It should be understood that the database connectivity test mentioned in the embodiments of this application refers to whether the connection between the project and the database, as well as database permissions and other functions, can be used normally in the early stages of project release. However, existing solutions require manual intervention to check and verify permissions. This results in a large investment of manpower, low efficiency, and a high risk of incorrect or missed permission requests.
[0058] To address the aforementioned problems, this application provides a database connectivity detection method, apparatus, electronic device, computer-readable storage medium, and computer program product, which will be described in detail below.
[0059] Please see Figure 1 , Figure 1 This is a schematic diagram of an implementation environment according to an embodiment of this application. The implementation environment includes a client 110 and a server 120, wherein the client 110 and the server 120 communicate via wired or wireless means.
[0060] Client 110 provides testers with basic functions such as inputting pre-configured script parameters, setting CNC permission point parameters, and inputting custom script parameters to set database detection items. It can also provide intelligent functions such as automatically executing script parameters, which are not available with existing technologies, bringing users a more intelligent automated detection function.
[0061] Server 120 is a standalone server used to execute pre-configured scripts to generate corresponding configuration files or modify script files, and determine the configuration information of the target database based on the configuration file. It then performs connectivity testing on the target database based on the configuration information and determines the connectivity of the target database based on the test results.
[0062] Server 120 determines whether the connectivity of the target database is normal based on the detection results output by the database response database connectivity detection, thereby completing the target database connectivity detection.
[0063] It should be noted that server 120 can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. There are no restrictions on this.
[0064] The database can be a relational database, a non-relational database, a key-value database, or a cloud database that provides cloud services, etc., and there are no restrictions here.
[0065] It should be understood that cloud technology refers to a hosting technology that unifies a series of resources such as hardware, software, and networks within a wide area network (WAN) or local area network (LAN) to achieve data computing, storage, processing, and sharing. Cloud technology is also a general term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies based on the cloud computing business model. These technologies can form resource pools, which can be used on demand, offering flexibility and convenience.
[0066] Figure 2 This is a flowchart illustrating a database connectivity detection method according to an exemplary embodiment of this application. This method is applicable to... Figure 1 The implementation environment shown, and by Figure 1 The method is specifically executed by server 120 in the illustrated embodiment environment. This method can also be applied to other implementation environments and executed by devices in other implementation environments; this embodiment does not limit this.
[0067] The following will describe in detail the methods proposed in the embodiments of this application, using a server as an exemplary execution entity. Figure 2 As shown, in an exemplary embodiment, the method includes steps S210 to S240, which are described in detail below:
[0068] Step S210: Execute the pre-configured script to generate the corresponding configuration file.
[0069] In this embodiment, the pre-configured script refers to a script pre-configured according to the database permissions required by the project to be tested. In other words, the pre-configured script is written according to the different database permissions required by the project. The server calls the corresponding compilation environment to execute the received pre-configured script to generate a configuration file in the corresponding format.
[0070] For example, during the pre-release phase of a project, script parameters for connectivity testing of the databases involved in the test run are pre-configured according to the project's operational requirements. These parameters include determining the corresponding check items and the permissions that need to be verified for each check item based on the project's transactions. Based on this, the configured script parameters are input into the client, and then the server executes them to generate the corresponding configuration file.
[0071] Step S220: Extract the configuration information of the target database contained in the configuration file;
[0072] The server extracts configuration information from the corresponding configuration file generated based on preset script parameters. This configuration information includes information about the target database for the project, the detection items for the target database, and the permissions for those detection items. The configuration file can be saved in a uniform format, or a file format adapted to the project type or environment can be generated.
[0073] For example, by configuring the corresponding script parameters for database permission verification of the project to be released, the server executes the configuration parameters to generate the corresponding configuration file. The server further extracts the configuration information related to the target database detection from the configuration file, and determines the detection items of the target database based on the configuration information, such as which permissions need to be detected for the target database, which data needs to be verified, etc.
[0074] Step S230: Perform connectivity detection on the target database based on the configuration information of the target database to obtain the detection results corresponding to the target database.
[0075] In this embodiment, the detection items of the target database are determined according to the configuration information included in the configuration file generated by executing the preset script. The corresponding detection tool is selected to detect the target database according to the detection items of the target database, and the detection results of the corresponding detection items of the target database are obtained according to the detection tool.
[0076] Specifically, before the project is released, corresponding target database detection script parameters are written according to the project requirements. For example, these detection script parameters are pre-configured default detection script parameters. That is to say, when the project needs to detect the connectivity with the corresponding target database, it can directly execute the script parameters corresponding to the pre-configured default detection items to generate the corresponding default configuration file. Then, the target database is detected according to the default detection items corresponding to the configuration information included in the default configuration file. When the detection results of the default detection items are consistent with the expected results, it is determined that the connectivity of the target database is normal.
[0077] Furthermore, before the project is released, the corresponding target database detection script parameters are customized according to the needs of the project launch. The corresponding configuration file is generated by executing the customized detection script parameters, and the detection items corresponding to the target database are determined according to the configuration information in the configuration file. Then, the detection tool is determined according to the detection items to detect the target database and obtain the corresponding detection results.
[0078] Step S240: If the detection result is consistent with the expected result, then the connectivity of the target database is determined to be normal.
[0079] Specifically, based on the configuration information in the configuration file, the corresponding detection tool is invoked to perform connectivity testing on the target database. Since different detection items correspond to different detection tools, in this embodiment, the detection results for each detection item of the target database are pre-set according to pre-configured script parameters. That is, each detection item has its corresponding detection result pre-set, and only the detection result that matches the expected detection result indicates that the detection item has passed the test. In other words, in this embodiment, when the detection results for all detection items corresponding to the configuration information in the configuration file match the expected results, it indicates that the connectivity of the target database is normal.
[0080] In this embodiment, corresponding script parameters are pre-configured according to the actual needs of the project. The pre-configured script parameters are automatically executed to generate a corresponding configuration file. Then, the target database and the detection items for the target database are determined based on the configuration file. The corresponding detection tools are called to perform tests on the target database based on the detection items. When the detection results match the expected results, the connectivity of the target database is determined to be normal. Thus, by executing the pre-configured parameters, connectivity testing of the target database can be performed automatically, supporting rapid access to the target database and execution of the detection items in the configuration file, avoiding omissions or low efficiency issues caused by manual application and manual testing.
[0081] Based on the above embodiments, in one exemplary embodiment provided in this application, the connectivity detection of the target database further includes permission point verification. Therefore, step S230 specifically includes steps S231 and S232, which are described in detail below:
[0082] Step S231: Determine the items to be detected in the target database based on the configuration information of the target database.
[0083] Specifically, script parameters are pre-configured according to the project's operational needs. Executing these pre-configured parameters generates a corresponding configuration file, which includes target database information, corresponding detection items for the target database, and the user account and password for that database. The detection items for the target database are determined based on the configuration information in the configuration file. These detection items include permission verification for the target database. The configuration information includes a step-by-step connection to the corresponding target database for each of the target database's detection items.
[0084] Step S232: Call the corresponding detection function to perform connectivity verification on the target database based on the items to be detected in the target database.
[0085] The system calls the corresponding detection functions to connect to and test the target database line by line according to the configuration items in the configuration file. For example, if the configuration information includes the default "select" permission detection for the database, the system calls the detection functions to perform line-by-line detection on the target database according to the configuration content in the configuration file.
[0086] It should be noted that the connectivity check of the target database based on the configuration includes the detection of target database permission points. For example, the name of the first table can be obtained through "show tables;" and the name of the first table can be obtained through "select *from".<table_name> The command "limit 1" will retrieve the name of a table in the target database. Other permission points are also verified using corresponding detection functions.
[0087] In this embodiment, corresponding script parameters are pre-configured according to the project's operational needs. Executing the pre-configured script parameters yields the corresponding configuration file. The configuration items in the configuration file determine the target database, the detection items for the target database, and the permission points for the target database. The detection function automatically obtains the configuration information and performs line-by-line detection on the target data. This not only avoids errors and omissions caused by manually checking the target database line by line, but also improves the efficiency of the target database detection.
[0088] Furthermore, based on the above embodiments, in one exemplary embodiment provided in this application, step S232 further includes steps S2321 and S2322, which are described in detail below:
[0089] Step S2321: Determine the detection level permissions of the target database according to the configuration information, wherein the detection level permissions include at least one of database level permissions, data table level permissions, data row level permissions, and data column level permissions;
[0090] Step S2322: Based on the detection level permission, call the corresponding detection function to perform connectivity detection on the target database.
[0091] It's important to clarify that a database is a structured collection of data. The simplest way to understand it is to think of a database as an Excel file: just as an Excel file has "workbooks," "columns," and "rows," a database also has "tables," "columns," and "rows." A database contains multiple tables, each containing rows and columns. A table can be understood as a data grid. The grid is first divided into different columns based on data categories, such as "class" and "student ID," and then each row stores data according to these columns. The column names in a table can also be called "fields." For example, we can say that a table has two columns, "class" and "student ID," or we can say that it has two fields, "class" and "student ID"—both expressions mean the same thing.
[0092] A project can have multiple database services. Databases offer many advantages, including overall data structuring, high data sharing, high data independence, and strong data control capabilities. In this embodiment, data independence refers to the relationship between data and the application (project). The data and its structure are stored in the database (on external storage) and managed by the database. The application (project) neither stores the data nor its logical structure. This not only ensures data independence but also reduces the risk of excessive server load caused by storing large amounts of data in the application (project).
[0093] As described above, a database system includes: databases, data tables, data rows, data columns, and data fields. The permissions for the target database in the corresponding configuration file are set according to the project's operational needs. These permissions vary in depth. In this embodiment, the detection permissions for the target database include: database-level permissions, table-level permissions, row-level permissions, and column-level permissions. This means that the data permissions involved in the project operation may exist in the entire target database, in one or more data tables within the target database, or in one or more columns and / or rows within the target database. The detection-level permissions for the target database are determined based on the configuration information, and the corresponding detection function is called to perform a connectivity test on the target database specified in the configuration file.
[0094] For example, script parameters are pre-configured according to the needs of project operation, and a corresponding configuration file is generated by executing these pre-configured script parameters. The server determines the target database that the project needs to connect to and the connection permission level for the target database based on the configuration information in the configuration file. For example, the configuration information in the configuration file can determine that the target databases are database A and database B. The permissions of database A include data table 1 (table1) and data table 2 (table2), and the permission level of database B is the entire database B. Permission point verification commands are then executed for database A and database B respectively. For example, in database A, the function "select * from" can be used to verify permissions.<table_name> The "limit1" option retrieves the name of the first data table (table1).
[0095] In this embodiment, the detection permission level of the target database is determined according to the configuration information in the configuration file, and the detection function is automatically determined according to the permission level of the target database to perform connectivity detection on the target database. This avoids the errors and inefficiencies caused by manually compiling a detection list for the target database, checking detection items, and manually checking each item one by one.
[0096] Furthermore, based on the above embodiments, in one exemplary embodiment provided in this application, step S2322 further includes steps S23221 and S23222, which are described in detail below:
[0097] Step S23221: Determine the target permission point corresponding to the target database based on the detection level, and call the detection function corresponding to the target permission point;
[0098] Step S23222: Execute the target permission point verification command against the target database based on the detection function, and write the corresponding execution result to the log file to determine the detection result corresponding to the target database based on the log file.
[0099] Please see Figure 3 Data Control Language (DCL) in SQL is a set of commands that control access rights to data. It controls a specific user account's control over database objects such as tables, stored procedures, and user-defined functions. It consists of the GRANT and REVOKE commands. Database Control Language (DCL) is a language used to set or change database user or role permissions, including statements such as GRANT, DENY, and REVOKE. By default, only administrators such as sysadmin, dbcreator, db_owner, or db_securityadmin have the authority to execute DCL statements. Data Manipulation Language (DML) allows users to perform basic database operations, such as querying, inserting, deleting, and modifying data in tables. In DML, applications can perform five operations on the database: insert, delete, update, sort, and check.
[0100] Please continue reading. Figure 3 After determining the target permission point corresponding to the target database, the corresponding detection function is called to verify the target permission point. This detection function can be a pre-encapsulated Database Control Language (DCL) or a database-specific detection tool; this application does not impose any restrictions. In this embodiment, taking the calling of the DCL (Data Control Language) interface in SQL as an example, the DCL executes the corresponding operations on the database based on the target permission point included in the configuration information. DQL (Data Query Language) standard syntax includes: SELECT select_list, [INTO new_table], FROM table_source, [WHERE search_condition], [GROUPBY group_by_expression], [HAVING search_condition], [ORDERBY order_expression[ASC|DESC]], etc.
[0101] For example, such as Figure 3As shown, authorization for DCL is obtained by calling the detection function. DCL directly operates on the target database and its tables. Data in the tables is queried using DQL. The most commonly used query statement is the "SELECT select_list" mentioned above. Data in the tables is added, deleted, and modified using DML. During the verification process, the execution results are written to the log file. The connectivity of the target database is determined by checking the execution results of the corresponding target permission points in the log file.
[0102] For example, such as Figure 4 As shown, by executing a pre-configured script, corresponding script parameters are pre-configured according to the needs of project operation. The execution of this pre-configured script generates a corresponding configuration file. The server determines the target database and its corresponding permission level based on the configuration information in the configuration file, and performs connectivity tests on the target database and its corresponding permission level. For example, based on the configuration information in the configuration file, the target databases can be identified as database 1 and database 2. The permissions for database 1 include table1, table2, and table3, as well as the permissions for the corresponding data rows (header 1 and header 2) in the data tables. The connectivity of the corresponding data rows in the target database tables is then verified using appropriate connectivity testing techniques.
[0103] In this embodiment, the target permission points of the target database are verified using the detection function (database operation language) corresponding to the target permission points in the configuration file. During execution, the verification results of the target permission points are written to a log file. By viewing the verification results in the log file, the connectivity of the target database can be determined. This avoids the inconvenience of manual testing.
[0104] Based on the above embodiments, such as Figure 5 As shown, in one exemplary embodiment provided in this application, connectivity detection further includes connectivity verification, that is, steps S2301 to S2303 are included before step S230, as detailed below:
[0105] Step S2301: Execute a database connection command to the target database using the account information and password information in the configuration file;
[0106] Step S2302: Based on the response from the target database, determine whether the target database can be connected normally;
[0107] Step S2303: If the determination is yes, then execute the step of determining the items to be detected in the target database based on the configuration information of the target database.
[0108] Specifically, before verifying the specific permission points of the target database, the process includes establishing a login connection to the target database based on the database type, database name, database IP address, database port, database username, database password, and table names specified in the configuration file. This connection is achieved by executing "mysql -h". <host> -P <port> -u <username> -p <password>-D<db_name> The command determines whether the target database can be logged into normally. If the target database can be logged into normally, permission verification for the items to be tested is performed on the target database.
[0109] In this embodiment, the login connection verification of the target database is performed using the target database username and password contained in the configuration file. This automatically verifies whether the target database can be logged into normally, avoiding the process of manual verification and the waste of resources caused by performing target database permission verification when login is not possible.
[0110] Further, please refer to Figure 6 Based on the above embodiments, in one exemplary embodiment provided in this application, step S220 further includes steps S221 to S223, which are described in detail below:
[0111] Step S221: Determine that the file format of the configuration file is a unified configuration format;
[0112] Step S222: If the determination is yes, then extract the configuration information of the target database from the configuration file;
[0113] Step S223: If the determination is negative, extract the configuration information of the target database from the configuration file according to the configuration information extraction method corresponding to the file format of the configuration file.
[0114] Based on the project's operational needs, corresponding script parameters are pre-configured. Executing these script parameters generates a configuration file in the corresponding format. While the configuration file can be configured using a unified format, different projects or deployment environments may require different file formats. In this embodiment, if the configuration file is configured according to a preset unified format, the configuration information related to the target database can be directly extracted from the configuration file configured according to the preset unified format.
[0115] As mentioned above, due to differences in projects or deployment environments, configuration files are configured using a file format compatible with the project. For configuration files not generated according to a unified configuration format, the configuration information is read and identified according to the configuration format of the corresponding project to obtain the configuration information of the target database.
[0116] For example, the project type is determined by its original configuration. Common project types include Node.js, Go, and PHP projects. It's worth noting that a Node.js project is a JavaScript runtime environment based on the Chrome V8 engine, used to easily build fast and scalable network applications. Node.js uses an event-driven, non-blocking input / output (I / O) model, making it lightweight and efficient, ideal for data-intensive real-time applications running on distributed devices. A Go project refers to a project developed using the Go language, which can shorten API response time and solve the problem of batch request timeouts. Go is easy to use, has efficient code description, unified coding standards, and is quick to learn. With minimal code, framework standardization can be achieved, and API business logic can be quickly built using unified standards. It can quickly build various general-purpose components and public libraries, further improving development efficiency and enabling mass production of features in specific scenarios. A PHP project refers to a project whose unique syntax blends C, Java, Perl, and PHP's own innovative syntax.
[0117] In other words, referencing Figure 7 By executing pre-configured script files, the configuration file formats for projects built using different programming languages will vary, and the extraction methods for configuration information from these files will also differ depending on the project type. If the pre-configured script is configured according to a pre-defined uniform format, the YAML configuration file is read directly, and the database configuration information is read and identified from it. If the pre-configured script is not configured according to the pre-defined uniform format, it indicates that the script is based on the original project configuration. In this case, the project type needs to be identified, and the target database configuration information in the configuration file needs to be read and identified according to the reading method corresponding to the project type. For example... Figure 7 The method shown determines the project type based on the project's original configuration. If it is identified as a Node.js project, a configuration file is generated according to the Node.js project configuration format, and the configuration information about the target database in the configuration file is read and recognized according to the Node.js project configuration format. If it is identified as a Go project, a configuration file is generated according to the Go project configuration format, and the configuration information about the target database in the configuration file is read and recognized according to the Go project configuration format. If it is identified as a PHP project, a configuration file is generated according to the PHP project configuration format, and the configuration information about the target database in the configuration file is read and recognized according to the PHP project configuration format. Of course, the technical solution provided in this embodiment is not limited to the above three types of projects. This technical solution is also applicable to other project types, which will not be described in detail here.
[0118] In this embodiment, by determining the project type, a configuration file is generated using a file format that is compatible with the project type. Furthermore, the configuration information of the target database is extracted from the configuration file using an extraction method that is compatible with the configuration file. This greatly improves the versatility of the solution, enabling different types of projects to perform connectivity tests with the target database using this solution.
[0119] Based on the above embodiments, please refer to Figure 8 In one exemplary embodiment provided in this application, a database connectivity detection method is proposed, which further includes steps S250 to S270, detailed as follows:
[0120] Step S250: If the output data of the target database is inconsistent with the expected data, an alarm message is sent. The alarm message includes alarm details for the network not having the corresponding detection permission level.
[0121] Step S260: Determine the new script parameters based on the alarm details;
[0122] Step S270: Write the new script parameters into the preset script and re-execute the preset script.
[0123] The output data of the target database is the test result of the target database. For example, during the connectivity test mentioned above, when logging into the target database using the user account and password specified in the configuration file, the login result is the output data of the target database. Similarly, when testing target permission points in the target database, the execution result of testing these points using the Database Operation Control Language (DLC) is also the output data of the target database. If the output data of the target database is inconsistent with the expected data, an alarm message is issued. The alarm message includes statistics on passed and failed target permission points and an explanation of the specific reasons for failure. Reasons for failure include: network policies preventing normal network communication between machines. If the above alarm message appears, the network device is checked and the target database connectivity test steps are re-executed. If an alarm indicating that a corresponding detection permission level does not exist appears, new script parameters are determined based on the non-existent detection permission level and written into the corresponding preset script for this project. The preset script is then re-executed to generate configuration information with that permission level and re-perform the connectivity test on the target database.
[0124] In this embodiment, by outputting corresponding alarm information for target databases that fail connectivity tests, and adjusting the test network environment and pre-configured scripts based on the alarm information, manual verification is avoided, effectively improving the efficiency of database connectivity testing.
[0125] Please see Figure 9 , Figure 9 This is a flowchart illustrating the overall service process of database connectivity detection in an exemplary embodiment provided in this application. Details are as follows:
[0126] Step S1. Enter the pre-configured script on the client;
[0127] Step S2. The server executes a pre-set script to generate a configuration file;
[0128] Step S3. The server extracts the configuration information of the target data from the configuration file according to the project format;
[0129] Step S4. The server accesses the target database using the user account and password in the target database configuration information;
[0130] Step S5. The server uses the database operation language to detect the target permission points of the target database in the configuration information.
[0131] Based on the project's operational needs, relevant script parameters are pre-configured, and the pre-configured script is input into the client. The server executes the pre-configured script to generate the corresponding configuration file. The server extracts the target database configuration information from the configuration file using an extraction method adapted to the project type. Then, it accesses the target database using the database user account and password in the target database configuration information and further interprets the target permission points in the target database. It then calls detection functions to check the target permission points in the target database. Specifically, it can use DCL (Database Control Language) to check the corresponding data tables and data segments in the target database, and writes the execution results to a log file. The connectivity of the target database is determined by the execution results recorded in the log file. In this way, by executing pre-configured script parameters, the connectivity of the target database required for project operation is automatically checked, avoiding errors and omissions caused by manual line-by-line checks.
[0132] It should be noted that although the steps of the method in this application are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.
[0133] According to one aspect of the embodiments of this application, please refer to Figure 10 A database connectivity detection device is provided, comprising:
[0134] The execution module 310 is used to execute a pre-configured script to generate a corresponding configuration file; the extraction module 320 is used to extract the configuration information of the target database contained in the configuration file; the testing module 330 is used to perform connectivity detection on the target database based on the configuration information of the target database to obtain the detection result corresponding to the target database; and the judgment module 340 is used to determine that the connectivity of the target database is normal if the detection result is consistent with the expected result.
[0135] According to one aspect of the embodiments of this application, the test module 330 specifically includes: a determination submodule, which determines the items to be tested in the target database based on the configuration information of the target database; and a permission point verification submodule, which calls the corresponding detection function to perform permission point verification on the target database according to the items to be tested in the target database.
[0136] According to one aspect of the embodiments of this application, the permission point verification submodule further includes: a determining unit, configured to determine the detection-level permissions of the target database based on configuration information, wherein the detection-level permissions include at least one of database-level permissions, data table-level permissions, data row-level permissions, and data column-level permissions; and a calling unit, configured to call the corresponding detection function based on the detection-level permissions to perform connectivity detection on the target database.
[0137] According to one aspect of the embodiments of this application, the calling unit is specifically used to: determine the target permission point corresponding to the target database according to the detection level, call the detection function corresponding to the target permission point; execute the target permission point verification instruction for the target database based on the detection function, and write the corresponding execution result into a log file, so as to determine the detection result corresponding to the target database according to the log file.
[0138] According to one aspect of the embodiments of this application, the apparatus further includes: a connection execution module, configured to execute a database connection instruction on a target database using account information and account password information in a configuration file; a connectivity judgment module, configured to determine whether the target database can be connected normally based on the response result of the target database; and a determination submodule, configured to, if the determination is yes, execute the step of determining the items to be detected in the target database based on the configuration information of the target database.
[0139] According to one aspect of the embodiments of this application, the extraction module 320 is further specifically used for: determining that the file format of the configuration file is a unified configuration format; if the determination is yes, then extracting the configuration information of the target database in the configuration file; if the determination is no, then extracting the configuration information of the target database from the configuration file according to the configuration information extraction method corresponding to the file format of the configuration file.
[0140] According to one aspect of the embodiments of this application, the apparatus further includes an alarm module 350 specifically configured to: send alarm information if the output data of the target database is inconsistent with the expected data, the alarm information including alarm details of the network not having the corresponding detection permission level; determine the new script parameters according to the alarm details; write the new script parameters into a preset script, and re-execute the preset script.
[0141] It should be noted that the database connectivity detection device and the database connectivity detection method provided in the above embodiments belong to the same concept. The specific operation methods of each module and unit have been described in detail in the method embodiments and will not be repeated here. In practical applications, the database connectivity detection device provided in the above embodiments can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. This is not a limitation here.
[0142] Embodiments of this application also provide an electronic device, including: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device enables the database connectivity detection method provided in the above embodiments.
[0143] Figure 11 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 11 The computer system 1200 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0144] like Figure 11 As shown, the computer system 1200 includes a Central Processing Unit (CPU) 1201, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 1202 or programs loaded from storage portion 1208 into Random Access Memory (RAM) 1203. The RAM 1203 also stores various programs and data required for system operation. The CPU 1201, ROM 1202, and RAM 1203 are interconnected via a bus 1204. An Input / Output (I / O) interface 1205 is also connected to the bus 1204.
[0145] The following components are connected to I / O interface 1205: an input section 1206 including a keyboard, mouse, etc.; an output section 1207 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1208 including a hard disk, etc.; and a communication section 1209 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1209 performs communication processing via a network such as the Internet. A drive 1210 is also connected to I / O interface 1205 as needed. Removable media 1211, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1210 as needed so that computer programs read from them can be installed into storage section 1208 as needed.
[0146] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1209, and / or installed from removable medium 1211. When the computer program is executed by central processing unit (CPU) 1201, it performs various functions defined in the system of this application.
[0147] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0148] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0149] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0150] Another aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned database connectivity detection method. This computer-readable storage medium may be included in the electronic device described in the above embodiments, or it may exist independently and not incorporated into the electronic device.
[0151] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the database connectivity detection method provided in the various embodiments described above.
[0152] The above description is merely a preferred exemplary embodiment of this application and is not intended to limit the implementation of this application. Those skilled in the art can easily make corresponding modifications or alterations based on the main concept and spirit of this application. Therefore, the scope of protection of this application should be determined by the scope of protection claimed in the claims.< / password> < / username> < / port> < / host>
Claims
1. A method of connectivity detection for a database, the method comprising: The method comprises the following steps: executing a pre-configured script to generate a corresponding configuration file; if the file format of the configuration file is a unified configuration format, extracting configuration information of a target database contained in the configuration file, and if the file format of the configuration file is not the unified configuration format, extracting the configuration information of the target database from the configuration file according to a configuration information extraction mode corresponding to the file format of the configuration file; determining a to-be-detected item of the target database based on the configuration information of the target database, wherein the to-be-detected item comprises a detection level permission of the target database, and the detection level permission comprises at least one of a database level permission, a data table level permission, a data row level permission and a data column level permission; performing connectivity detection on the target database based on the detection level permission by calling a corresponding detection function, to obtain a detection result corresponding to the target database; if the detection result is consistent with an expected result, determining that the connectivity of the target database is normal.
2. The method of claim 1, wherein, The connectivity detection based on the detection level permission by calling the corresponding detection function comprises the following steps: determining a target permission point corresponding to the target database according to the detection level, and calling a detection function corresponding to the target permission point; based on the detection function, executing a target permission point verification instruction on the target database, and writing a corresponding execution result into a log file, so as to determine the detection result corresponding to the target database according to the log file.
3. The method of claim 1, wherein, The connectivity detection further comprises connectivity verification, and before determining the to-be-detected item of the target database based on the configuration information of the target database, the method comprises the following steps: executing a database connection instruction on the target database through account information and account password information in the configuration file; judging whether the target database can be normally connected according to a response result of the target database; if the judgment is yes, executing the step of determining the to-be-detected item of the target database based on the configuration information of the target database.
4. The method of claim 1, wherein, The method further comprises the following steps: if output data of the target database is inconsistent with expected data, sending an alarm information, wherein the alarm information comprises an alarm detail of a non-existing detection permission level; determining a new script parameter according to the alarm detail; writing the new script parameter into a pre-set script, and re-executing the pre-set script.
5. A database connectivity detection apparatus, characterized by, The method comprises the following steps: an execution module, configured to execute a pre-configured script to generate a corresponding configuration file; an extraction module, configured to extract configuration information of a target database contained in the configuration file if the file format of the configuration file is a unified configuration format, and extract the configuration information of the target database from the configuration file according to a configuration information extraction mode corresponding to the file format of the configuration file if the file format of the configuration file is not the unified configuration format. The test module is configured to determine a to-be-detected item of the target database based on configuration information of the target database, the to-be-detected item including detection level permissions of the target database, wherein the detection level permissions include at least one of a database level permission, a data table level permission, a data row level permission, and a data column level permission. The test module is further configured to perform connectivity detection on the target database based on the detection level permissions to obtain a detection result corresponding to the target database. The judgment module is configured to determine that the connectivity of the target database is normal if the detection result is consistent with an expected result.
6. An electronic device, comprising: The electronic device comprises: one or more processors; a storage device configured to store one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the database connectivity detection method according to any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, A computer-readable instruction is stored thereon, which, when executed by a processor of a computer, causes the computer to perform the database connectivity detection method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Fault detection method and device for database cluster
CN105429826A
Database OLTP reference performance test method and system and related components
CN111625434A