Database script deployment method and device, server and storage medium
By using an automated database script deployment method that leverages indexes and join string arrays, the problems of tedious and error-prone manual operations are solved, achieving efficient and accurate database script deployment while supporting flexibility and security across multiple environments.
Patent Information
- Application Number
- CN202511424993.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-30
- Publication Date
- 2026-02-13
AI Technical Summary
In existing technologies, database script deployment relies on manual operation, which is cumbersome, inefficient and prone to errors. Especially in multi-environment collaborative development and version iteration upgrade scenarios, manual switching of databases and users is frequent, which consumes time and resources.
By traversing file names through the first server, extracting index query connection string information, and automating the deployment of database scripts, the deployment efficiency and accuracy are improved by utilizing indexes and connection string arrays. This supports multi-environment deployment and enhances the security and maintainability of connection string information.
It enables automated batch deployment of database scripts, improving deployment efficiency and accuracy, reducing manual intervention, enhancing the security and maintainability of connection string information, and supporting the flexibility of multi-environment deployment.
Smart Images

Figure CN121523698A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of database, and particularly relate to a database script deployment method and device, a server and a storage medium. BACKGROUND
[0002] In the process of operation and development of the database deployed on the server, it is a common deployment scenario to frequently execute a large number of database scripts belonging to different databases, especially in the application scenarios of multi-environment collaborative development, version iteration upgrade or data migration.
[0003] At present, the deployment operation mainly depends on manual operation for this deployment scenario. For example, when different database scripts are directed to different databases or different users in the same database, manual database script deployment operation needs to frequently switch the database or the database user. In this way, manual operation is tedious and inefficient. In addition, manual operation is prone to operation errors. SUMMARY
[0004] Embodiments of the present application provide a database script deployment method and device, a server and a storage medium, which can automatically deploy database scripts and improve the accuracy and efficiency of database script deployment.
[0005] To achieve the above purpose, embodiments of the present application adopt the following technical solutions:
[0006] In a first aspect, a database script deployment method is provided, which is applied to a first server. The first server includes a plurality of database scripts to be deployed. The first server is connected with a second server, and the second server includes a database. The first server iterates a plurality of file names and extracts a first index from a first file name currently iterated. One file name corresponds to one database script to be deployed, and the first file name corresponds to a first database script to be deployed. Then, the first server queries first connection string information of the first database script to be deployed based on the first index, so as to deploy the first database script to be deployed to a target database in the second server based on the first connection string information. In this way, the first server can deploy all the database scripts to be deployed corresponding to the iterated file names on the second server, thereby improving the efficiency and accuracy of database script deployment.
[0007] In the implementation manner, the first server can realize the deployment of the to-be-deployed database script corresponding to each file name by traversing the plurality of file names. In this way, the automation processing of batch deployment of the database script file can be realized, and the deployment efficiency is improved. Moreover, the above scheme decouples the to-be-deployed database script and the database connection string information through the first index, which can enhance the security and maintainability of the connection string information, and make the above method applicable to multi-environment deployment, and has good expansibility and flexibility.
[0008] In a possible implementation manner of the first aspect, the first server includes a plurality of to-be-deployed database scripts. Specifically, the first directory of the first server includes a plurality of database script files, and each database script file includes a to-be-deployed database script. Then, correspondingly, before traversing the file names of the plurality of to-be-deployed database scripts, the first server can also read the plurality of database script files from the first directory, generate a file name list, and the file name list includes the plurality of file names. Moreover, after that, the first server can traverse the plurality of file names in the file name list to realize the traversal process of the plurality of file names.
[0009] In the above scheme, the first directory can generate the file name list including the plurality of database script file names, and the traversal of each file name can be realized based on the file name list. In this way, the first server can accurately deploy each to-be-deployed database script file, and the omission is avoided. In this way, the accuracy of database maintenance can be significantly improved.
[0010] In a possible implementation manner of the first aspect, before reading the plurality of database script files from the first directory to generate the file name list, the first server can also detect whether the database script file exists in the first directory.
[0011] In some examples, the first server can detect whether the database script file exists in the first directory by detecting whether the first directory is empty.
[0012] In the above scheme, by detecting whether the database script file exists in the first directory, the invalid deployment operation can be effectively prevented, the resource waste is avoided, and the reliability of the automation process is significantly enhanced.
[0013] In a possible implementation manner of the first aspect, the first server includes an array of connection string information. Hereinafter, the array of connection string information can be referred to as a connection string array. When the first server is querying the first connection string information of the first to-be-deployed database script based on the first index, the first connection string information can be queried from the array based on the first index.
[0014] In the above scheme, the first server can pre-store a connection string array, and then query the corresponding connection string information in the connection string array through indexing, so as to avoid the security risk caused by the leakage of the connection string information. Moreover, the connection string information can be quickly acquired, so as to improve the execution efficiency in a large-scale deployment scenario.
[0015] In a possible implementation manner of the first aspect, the connection string information includes at least one of the following: a server address, a port number, a database name, a username, and a user password. The array includes at least one of the following arrays: a server address array, a port number array, a database name array, a username array, and a user password array.
[0016] In the above scheme, the connection string information stored in the form of an array is referred to as a connection string array. In this way, the storage of the connection string information is convenient for management.
[0017] In a possible implementation manner of the first aspect, after the first server deploys the first to-be-deployed database script to the target database in the second server based on the first connection string information, the first server can further determine whether the file name traversal is completed. In the case where the file name traversal is not completed, the first server can continue to traverse the plurality of file names.
[0018] In the case where the file name traversal is completed, the first server can stop traversing the plurality of file names.
[0019] In the above scheme, the first server can determine whether the file name traversal is completed, so as to ensure that the entire deployment process can automatically and continuously process the plurality of script files without manual intervention. In this way, it can be ensured that all to-be-deployed database scripts are processed, thereby ensuring the completeness of the deployment.
[0020] In a possible implementation manner of the first aspect, the first server can ensure that each deployment process is effective through the following process. The first server can first detect whether the type of the character set in the first to-be-deployed database script is a preset type, so that, in the case where the type of the character set in the first to-be-deployed database script is the preset type, the first server can continue to deploy the first to-be-deployed database script to the target database in the second server based on the first connection string information.
[0021] In the case where the type of the character set in the first to-be-deployed database script is not the preset type, the first server can no longer deploy the first to-be-deployed database script to the target database in the second server based on the first connection string information. In this way, it can be avoided that the first to-be-deployed database script cannot be deployed to the target database in the second server based on the first connection string information, so as to avoid the waste of resources and time, thereby effectively improving the deployment efficiency.
[0022] In a second aspect, a database script deployment apparatus is provided. The apparatus is applied to a first server, wherein the first server comprises a plurality of database scripts to be deployed, and the first server is connected to a second server, wherein the second server comprises a database. The apparatus comprises:
[0023] a traversing module configured to traverse the plurality of file names, one file name corresponding to one database script to be deployed;
[0024] an index extracting module configured to extract a first index from a first file name currently traversed, the first file name corresponding to a first database script to be deployed;
[0025] a querying module configured to query first connection string information of the first database script to be deployed based on the first index;
[0026] a deployment module configured to deploy the first database script to be deployed on a target database in the second server based on the first connection string information.
[0027] In a third aspect, a server is provided. The server comprises a memory and at least one processor. The memory is in communication with the processor. The memory is configured to store computer program codes, the computer program codes comprising computer instructions. When the processor executes the computer instructions, the server performs the method according to the first aspect and any possible implementation manner thereof.
[0028] In a fourth aspect, a computer readable storage medium is provided. The computer readable storage medium stores computer instructions. When the computer instructions are executed by a processor, the computer instructions are used to implement the method according to the first aspect and any possible implementation manner thereof.
[0029] In a fifth aspect, a computer program product is provided. When the computer program product is run on a computer / executed by a processor of a computer, the computer program product implements the method according to the first aspect and any possible implementation manner thereof. The computer can be the server according to the second aspect and any possible implementation manner thereof.
[0030] It can be understood that the database script deployment apparatus according to the second aspect, the server according to the third aspect, the computer readable storage medium according to the fourth aspect, and the computer program product according to the fifth aspect can achieve the beneficial effects as described in the first aspect and any possible implementation manner thereof, which will not be described herein. BRIEF DESCRIPTION OF DRAWINGS
[0031] Figure 1 FIG. 1 is a schematic diagram of a database operation and maintenance system according to an embodiment of the present application;
[0032] Figure 2 A flowchart of a database script deployment method provided by an embodiment of the present application Figure 1 ;
[0033] Figure 3 A flowchart of a database script deployment method provided by an embodiment of the present application Figure 2 ;
[0034] Figure 4 A flowchart of a database script deployment method provided by an embodiment of the present application Figure 3 ;
[0035] Figure 5 A structural diagram of a database script deployment device provided by an embodiment of the present application
[0036] Figure 6 A structural diagram of a server provided by an embodiment of the present application DETAILED DESCRIPTION
[0037] Hereinafter, the terms "first" and "second" are used only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined with "first" and "second" can explicitly or implicitly include one or more of the features. In the description of the embodiments, unless otherwise specified, the meaning of "a plurality of" is two or more.
[0038] The exemplary embodiments will be described in detail below with reference to the drawings. In the following description, the same numbers are used to designate the same elements, unless otherwise specified, and the same numbers in different drawings designate the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all the embodiments consistent with the present application. Rather, they are merely examples of devices and methods consistent with some aspects of the present application, as detailed in the appended claims.
[0039] In the technical solutions provided by the embodiments of the present application, the collection, storage, use, processing, transmission, provision and disclosure of data or user data and other information involved in the technical solutions comply with relevant legal regulations and do not violate public order and good customs.
[0040] It should be noted that in the embodiments of the present application, some software, components, models and other existing industry solutions may be mentioned, which should be considered as exemplary, and the purpose is only to illustrate the feasibility of the implementation of the technical solutions of the present application, but does not mean that the applicant has or will necessarily use the solutions.
[0041] In the process of database system operation and development, it is a common deployment scenario to frequently execute a large number of database scripts belonging to different databases, especially in the application scenarios of multi-environment collaborative development, version iteration upgrade or data migration.
[0042] At present, the deployment operation mainly depends on manual operation for this deployment scenario. For example, when different database scripts belong to different databases or belong to different users in the same database, manual database script deployment operation needs to frequently switch databases or database users.
[0043] However, in the process of manually deploying database scripts, the steps of operating personnel need to operate are cumbersome, and operation errors are prone to occur.
[0044] For example, there are three independent databases running on the same server, but the three independent databases belong to different logical libraries. For example, the three databases are user database, order database and inventory database. In practice, the three databases may need to be operated respectively. For example, it is necessary to modify the user level calculation method in the user database, add discount information and discount calculation logic to each order in the order database, and create an inventory warning view in the inventory database.
[0045] In some implementations, the operator needs to input the connection string information of the server address, port, username and user password of the database script to be deployed in the database operation tool to connect the server and obtain the permission to deploy the database script on the server. In this process, if the operator makes a mistake in any of the server address, port, username or user password, the server connection will fail or the deployment permission will fail. Then, it is necessary to check and re-enter.
[0046] After the operator successfully obtains the deployment permission, the operator needs to select the order database and open and execute script 1 (for adding discount information and discount calculation logic to each order in the order database) in the order database. Moreover, after the complete execution of script 1, the operator also needs to check the execution result. In this process, the operator needs to select the correct database to avoid executing script 1 in the wrong database, which will result in the failure to add discount information and discount calculation logic to each order in the order database. Secondly, the process of executing script 1 consumes a lot of time, and the operator needs to wait for the execution to be completed before proceeding to the next operation, during which other database scripts cannot be deployed. After that, if script 1 fails, the operator also needs to repeat the operation of script 1. Based on the above process, it can be seen that the operator needs to perform complicated operations and consume a lot of time in the process of deploying script 1.
[0047] After the execution of the script 1 is successful, the operator needs to switch from the order database to the user database. In some embodiments, if the database operation tool currently used by the operator does not support quick switching of the database, the operator also needs to disconnect the connection established with the second server first. Then, the second server address, port, username and password need to be re-inputted, and here, the username and password inputted by the operator need to correspond to the user database.
[0048] After switching from the order database to the user database, the operator also faces the above-mentioned problems in the process of deploying the to-be-deployed database script in the user database. And after the successful modification of the user level calculation method in the user database, the operator also needs to switch from the user database to the inventory database to create an inventory early warning view for the inventory database. The whole process needs the operator to perform frequent database switching operations. And the operator needs to input a large amount of data of the same type but different content, such as different usernames and passwords for different databases, which is easy to cause input errors and lead to the failure of the database script deployment.
[0049] In addition, since there are many database scripts to be deployed, the operator needs to pay attention to which database script is currently being deployed at all times, so the operator needs to be highly concentrated to avoid operation errors.
[0050] And the operation process needs to consume a lot of time, resulting in low efficiency of the database script deployment.
[0051] To solve the above-mentioned problems, the present application provides a database script deployment method. The method is applied to a first server. The first server includes a plurality of to-be-deployed database scripts. And the first server is connected with a second server, and the second server includes a database. The first server iterates a plurality of file names and extracts a first index from a first file name currently iterated. Wherein, one file name corresponds to one to-be-deployed database script, and the first file name corresponds to a first to-be-deployed database script. Then, the first server queries first connection string information of the first to-be-deployed database script based on the first index, so as to deploy the first to-be-deployed database script to a target database in the second server based on the first connection string information. In this way, the first server can deploy all the to-be-deployed database scripts corresponding to the iterated file names to the second server, thereby improving the efficiency and accuracy of the database script deployment.
[0052] Hereinafter, the database script deployment method provided by the embodiments of the present application will be introduced in combination with the drawings.
[0053] As Figure 1As shown, the first server 100 is equipped with database operation tools. These tools, for example, could be a database client.
[0054] In some embodiments, the first server 100 may be a Linux server.
[0055] The first server 100 is connected to the second server 200. For example, the first server 100 and the second server 200 can be connected via a network.
[0056] The database script deployment method provided in this application embodiment can be written as a shell script. Thus, the first server can execute the database script deployment method by running the written shell script.
[0057] like Figure 2 As shown, the database script deployment method executed by the first server may include the following steps:
[0058] S101, Traverse multiple file names.
[0059] Each file name corresponds to a database script to be deployed.
[0060] In some embodiments, the first server may obtain a first directory, which includes the database script to be deployed, before traversing multiple file names.
[0061] In some embodiments, the first server can obtain a first directory through operator input. For example, the first server can display a directory input box so that the operator can enter the first directory.
[0062] As in the aforementioned embodiment, if the second server runs three independent databases—a user database, an order database, and an inventory database—and operators need to maintain these three databases, the first directory may include database scripts that need to be deployed in these three databases.
[0063] In other embodiments, the directory input box displayed by the first server may include a confirmation control. When an operator enters a first directory into the directory input box and triggers the confirmation control, the first server can obtain the first directory.
[0064] In other implementations, the confirmation control may also be referred to as the submission control, but this application does not specifically limit the name of the control.
[0065] In some embodiments, if the first server has obtained the first directory, the first server can read multiple database script files from the first directory and generate a list of filenames, which includes multiple filenames.
[0066] In some embodiments, before reading the plurality of database script files from the first directory and generating the list of file names, the first server can also detect whether the database script files exist in the first directory.
[0067] In other embodiments, the first server can obtain the first directory through a pre-specified address. For example, when the first directory is stored in a first address, the first directory can be obtained from the first address.
[0068] S102, extracting a first index from the first file name currently traversed.
[0069] The first file name corresponds to the first database script to be deployed.
[0070] The file name includes an index, which is used to locate specific connection string information in the connection string array. In some embodiments, the list of file names includes a plurality of file names, and the first file name currently traversed is recorded as the first file name. After traversing the first file name, the first index corresponding to the first file name, i.e., the index corresponding to the database script to be deployed, can be obtained based on the first file name.
[0071] The index is a numerical number used to uniquely identify the position of the connection string information of each database script in the connection string array. For example, when the connection string array is ["connection string information A", "connection string information B", "connection string information C"], index = 1 can refer to the first data element in the connection string array, i.e., "connection string information A", and index = 2 can refer to the second data element in the connection string array, i.e., "connection string information B".
[0072] Since the index is a simple integer, it can uniquely and accurately point to a specific data element in the connection string array. Therefore, in the above embodiments, the first server can quickly access the connection string information of the database script through the index.
[0073] In the above embodiments, the storage location of the connection string array can depend on the actual database architecture design, security requirements, and deployment environment. For example, in a local development or test environment, the storage location of the connection string array can be in a configuration file. For another example, in a production environment, the storage location of the connection string array can be configured in an environment variable. The storage location of the connection string array is not specifically limited in the embodiments of the present application.
[0074] After obtaining the first index, the following S103 can be performed:
[0075] S103, querying the first connection string information of the first database script to be deployed based on the first index.
[0076] The first server includes an array of connection string information, i.e., a connection string array. In this way, the first server can query the first connection string information from the connection string array based on the first index.
[0077] The connection string information includes at least one of the following: a server address, a port number, a database name, a username, and a user password.
[0078] Correspondingly, the array includes at least one of the following arrays: a server address array, a port number array, a database name array, a username array, and a user password array.
[0079] In some embodiments, the connection string array can be defined in a declared manner to complete the pre-configuration of the connection string array.
[0080] For example, a database name array corresponding to a database script to be deployed is declared, and multiple array elements included in the array are the names of multiple databases. A username array is declared, and multiple array elements included in the array are multiple user names. A user password array is declared, and multiple array elements included in the array are multiple user passwords. A server address array is declared, and multiple array elements included in the array are the addresses of multiple servers on which databases are deployed. A port number array is declared, and multiple array elements included in the array are the port numbers for accessing the multiple servers, respectively.
[0081] In the database operation and maintenance scenario, the connection string information required for configuring a database generally includes data of the types of the server address array, the port number array, the database name array, the username array, and the user password array. Among them, the specific values of the connection string information can change, for example, after the password is modified, the value of the password data can change. The types of the connection string information will not easily change dynamically with the running environment and the running progress during the running of the database script. Therefore, the array can be used to store the connection string information. The connection string information stored in the array is referred to as the connection string array. In this way, the storage of the connection string information is facilitated.
[0082] S104, deploying the first database script to be deployed to a target database in the second server based on the first connection string information.
[0083] In some embodiments, the first server can run the first database script to be deployed based on the first connection string information, and after the running of the first database script to be deployed is completed, the first database script to be deployed can be deployed to the target database in the second server.
[0084] In some embodiments, in order to detect whether the first to-be-deployed database script can be normally deployed, the first server can further detect whether the type of the character set in the first to-be-deployed database script is a preset type. If the type of the character set in the first to-be-deployed database script is the preset type, the first to-be-deployed database script can be deployed to the target database in the second server based on the first connection string information.
[0085] A character set is a collection of characters, each character set contains a specific set of characters, and different character sets may differ in the number of characters they include. In the field of computer science and information technology, a character set is a basic concept for representing and storing various characters, punctuation marks, graphical symbols, numbers, etc. The types of character sets can include American Standard Code for Information Interchange (ASCII), Chinese Character Encoding Character Set for Information Interchange (GB2312), Simplified Chinese (zh CN), Big Five or Five Big Code (BIG5), Information Technology Chinese Character Encoding Character Set (GB18030), Universal Code or Universal Code (Unicode), etc.
[0086] In some embodiments, after the first server obtains the character set of the to-be-deployed database script file, the first server can determine the type of the character set of the to-be-deployed database script file. After determining the type of the character set of the to-be-deployed database script file, the first server can determine whether the type of the character set of the to-be-deployed database script file is a processable character set type.
[0087] In the case where the type of the character set of the to-be-deployed database script file is not a processable character set type, the first server stops processing the current to-be-deployed database script.
[0088] In some embodiments, after the first server stops processing the current to-be-deployed database script, the first server can further determine whether the file name traversal is complete. In the case where the traversal is not complete, the first server continues to traverse the plurality of file names to continue processing the next to-be-deployed database script. In the case where the traversal is complete, the first server can stop traversing the plurality of file names.
[0089] In some embodiments, after the first server deploys the to-be-deployed database script currently being processed, the first server can determine whether the file name traversal is complete. In the case where the traversal is not complete, the first server continues to traverse the remaining file names. In the case where the traversal is complete, the first server can stop traversing the file names.
[0090] In the above embodiment, in the case of batch deploying a plurality of to-be-deployed database scripts, only the above S101-S104 needs to be repeatedly executed, so as to complete the implementation of deploying each first to-be-deployed database script corresponding to a first file name into a corresponding database. In this way, manual operation is not required, and the efficiency of script deployment is improved.
[0091] In addition, in this way, each deployment process can be isolated from each other, so that the operator can more conveniently distinguish the deployment processes of different to-be-deployed database scripts. For example, the first server retains a corresponding running log after executing S101-S104 once, so that the operator can clearly see the relevant content in each deployment process based on the independent running log and the like, so as to facilitate maintenance and improve the traceability of database script deployment.
[0092] In some embodiments, in the process of deploying the first to-be-deployed database script into the target database in the second server based on the first connection string information, the first server can first detect whether the first to-be-deployed database script can be normally deployed into the target database in the second server, and only in the case of a normal deployment, the first to-be-deployed database script is deployed into the second server. In this way, the waste of time resources due to abnormal deployment can be avoided, and the efficiency is improved.
[0093] For example, the first server can correspondingly acquire the type of the character set of the to-be-deployed database script file through the content of the to-be-deployed database script file. Then, the first server judges whether the type of the character set is a preset type. In the case where the first server judges that the type of the character set is the preset type, the first server can continue to deploy the to-be-deployed database script file into the second server. In the case where the first server judges that the type of the character set is not the preset type, the first server can no longer deploy the to-be-deployed database script file being currently deployed.
[0094] In the case where the type of the character set of the to-be-deployed database script file is a processable character set type, the first server can continue to deploy the to-be-deployed database script being currently processed.
[0095] For example, the type of the character set can be acquired first, and then it is detected whether the type of the character set of the to-be-deployed database script file is a processable character set type, and the type of the character set is output. For example, the type of the character set is output as Simplified Chinese (zh CN).
[0096] The processable character set type can be preset. For example, if the processable character set type is Unicode Transformation Format-8-bit (UTF-8) or ASCII, the character set type of the sql file can be acquired first, and it is checked whether the character set type is UTF-8 or ASCII.
[0097] If the character set type of the sql file is UTF-8 or ASCII, subsequent steps are continued. For example, an environment variable can be set to a first value to inform the current database to use the first character set type.
[0098] In some embodiments, if the character set type of the sql file is not UTF-8 or ASCII, an environment variable LANG can be set to a second value to inform the current database to use the second character set type.
[0099] In other embodiments, if the character set type of the sql file is not UTF-8 or ASCII, it is further checked whether it is GB2312, GB18030 or Chinese National Standard GBK. If yes, the environment variable LANG can be set to a third value to inform the current database to use the third character set type, and if not, the environment variable LANG can be set to a fourth value to inform the current database to use the fourth character set type.
[0100] In some embodiments, if the character set type of the sql file is not UTF-8 or ASCII and cannot be converted by the above code, an error message can be output to prompt that the character set type is not a preset type.
[0101] Through the above steps, the character set type used by the database can be specified as the first value when the character set type of the sql file is the first preset character set type, and the character set type used by the database can be specified as the second value when the character set type of the sql file is not the first preset character set type but the second preset character set type. Moreover, when the character set type of the sql file is not the first preset character set type nor the second preset character set type and cannot be converted, it indicates that the database cannot execute the sql file. At this time, an error prompt can be issued to facilitate the administrator to handle it in time.
[0102] In some embodiments, whether the database script file to be deployed is executable can be determined by a command line parameter in the database script file to be deployed.
[0103] Exemplarily, it can be checked whether the number of command line parameters in the database script file to be deployed is the preset number. If it is not equal to the preset number, error information can be outputted to prompt that the database script file to be deployed cannot be deployed, and the current database script file is not deployed any more.
[0104] In some embodiments, it can also be checked whether the encoding in the database script file to be deployed is valid. In the case that the encoding is valid, the database script file to be deployed can be continuously deployed, and in the case that the encoding is invalid, the current database script file is not deployed any more.
[0105] In some embodiments, in the case that the encoding in the database script file to be deployed is invalid, the sql file can also be format-converted so that the sql file can be executed by the database. For example, the format of the script file that can be executed by the database is unix format, but the format of the current sql file is DOS format, so the sql file can be converted from DOS format to unix format first. In the case that the format conversion is successful, the database script file to be deployed can be continuously deployed. For example, in the case that the format conversion is successful, the first server can log in the database through the index corresponding username, password and connection string, and send the format-converted sql file to the database, so that the database can execute the sql file.
[0106] In the above embodiments, in the case that the format conversion fails, the current database script file is not deployed any more.
[0107] In the above embodiments, the format of the outputted message can be set. The format of the outputted message includes the allowed interpretation escape character of the outputted information, the text color of the outputted information, and the output type (such as standard output, standard error) of the outputted information.
[0108] In the above embodiments, the first server can accurately obtain the connection string information of the database script based on the index corresponding to the database script to be deployed, that is, the address of the second server, the port number of the second server, the database name corresponding to the database script to be deployed, the username corresponding to the database script to be deployed, and the password. Then, the first server can connect to the second server based on the connection string information of the database script, so as to deploy the database script to be deployed to the second server. In this way, the situation of connecting to the second server multiple times or obtaining the authorization of the second server multiple times can be avoided.
[0109] In some embodiments, as shown in FIG. 8, the first server can perform the following steps to implement the database script deployment method provided in the embodiments of the present application. Figure 3
[0110] S201, obtaining a first directory.
[0111] S202. Determine whether the first directory is not empty and contains a database script file.
[0112] If the first directory is not empty and the database script file does not exist, the first server can terminate the process.
[0113] If the first directory is not empty and a database script file exists, the first server can execute the following S203:
[0114] S203. Generate a list of filenames based on all database scripts to be deployed in the first directory.
[0115] As shown in the previous example, this file name list includes the file names of all database scripts to be deployed.
[0116] S204. Initialize the traversal value k to 1.
[0117] S205. Determine whether k is less than or equal to the total number K of all database scripts to be deployed included in the filename list.
[0118] The first server can terminate the process if k is not less than or equal to the total number K of all database scripts to be deployed included in the filename list.
[0119] If k is less than or equal to the total number K of all database scripts to be deployed included in the filename list, the first server executes the following S206:
[0120] S206. Get the file name of the kth database script to be deployed from the file name list.
[0121] S207. Obtain the index corresponding to the kth database script to be deployed.
[0122] S208. Deploy the k-th database script to be deployed in the second server based on the k-th database script to be deployed and its corresponding index.
[0123] In some embodiments, such as Figure 4 As shown, the first server can obtain the k-th database script to be deployed and its corresponding index. Then, the first server can obtain the corresponding character set based on the k-th database script to be deployed, and obtain the corresponding connection string information from the index corresponding to the k-th database script to be deployed. Based on the connection string information corresponding to the k-th database script to be deployed, the first server can run the k-th database script to be deployed, thereby realizing the deployment of the k-th database script to be deployed on the second server.
[0124] S209. Update the value of k to k+1.
[0125] Afterwards, the first server re-executes S205.
[0126] The first server can complete the deployment of one to-be-deployed database script on the second server each time the steps of S205-S209 are executed. Until the value of k is not less than or equal to the total number K of all to-be-deployed database scripts included in the file name list, the first server can complete the deployment of all to-be-deployed database scripts.
[0127] After obtaining the first parameter as the SQL file directory, parameter checking can be performed, and a user keyword array can be defined. Afterwards, the absolute path of the current script is obtained. In some embodiments, parameter verification can be performed first to check whether the number of script parameters is 1. If the number of parameters is not equal to 1, error information is printed to prompt the operator to use it correctly. And at this time, the script execution is terminated immediately.
[0128] In some embodiments, the user configuration can also be initialized, so that the database script deployment method provided by the embodiments of the application is more flexible. For details, please refer to the related embodiments of S103 in the above embodiments, which will not be repeated here.
[0129] Afterwards, a user keyword regular expression is generated. The user keyword regular expression can be used to flexibly match the user identifier.
[0130] Afterwards, the directory is securely created, and if it exists, it is not created. Specifically, it can be checked first whether the target directory exists in the directory input by the user. If the target directory does not exist, the directory is created. In this way, whether the target directory exists or not, it can ultimately be ensured that the directory exists and no redundant operation or error is generated.
[0131] In some embodiments, the file name can be parsed to determine the user to which the database script file belongs. Specifically, the structured information in the file name can be accurately extracted based on the hierarchical peeling method of the naming rule. In this way, the user to which the database script file belongs can be determined.
[0132] Afterwards, the first server can match the to-be-deployed database script file, i.e., the SQL file, according to the determined username. Specifically, the first index can be extracted according to the file name of the database script file. This code can traverse the file path of the database script file to traverse each index in the username array. And the user identifier can be extracted. If the currently determined username is the same as the extracted user identifier, it can be determined that the to-be-deployed database script file corresponding to the user identifier corresponds to the username, and then the to-be-deployed database script can be deployed to the database corresponding to the determined username. In this way, it can be ensured that the to-be-deployed database script can be accurately deployed to the corresponding database.
[0133] Figure 5 This is a schematic diagram of the structure of a database script deployment device 500 provided in an embodiment of this application. Figure 5 As shown, the database script deployment device 500 includes: a traversal module 501, an index extraction module 502, a query module 503, and a deployment module 504.
[0134] The traversal module 501 is used to traverse multiple file names, with each file name corresponding to a database script to be deployed.
[0135] Index extraction module 502 is used to extract the first index from the first file name currently traversed, where the first file name corresponds to the first database script to be deployed;
[0136] Query module 503 is used to query the first connection string information of the first database script to be deployed based on the first index;
[0137] Deployment module 504 is used to deploy the first database script to be deployed to the target database in the second server based on the first connection string information.
[0138] In other embodiments, the first server includes multiple database scripts to be deployed. For example, a first directory of the first server includes multiple database script files, each containing one database script to be deployed. In this case, such as... Figure 5 As shown, the database script deployment device 500 also includes a file name list generation module 505.
[0139] The filename list generation module 505 is used to read multiple database script files from the first directory and generate a filename list, which includes multiple filenames.
[0140] In the above embodiment, the traversal module 501 is also used to traverse multiple file names in the file name list.
[0141] In other embodiments, such as Figure 5 As shown, the database script deployment device 500 also includes a script file detection module 506.
[0142] The script file detection module 506 is used to detect whether a database script file exists in the first directory.
[0143] In other embodiments, the first server includes an array of connection string information, and the query module 503 is further configured to query the first connection string information from the array based on a first index.
[0144] In other embodiments, such as Figure 5As shown, the database script deployment apparatus 500 further includes a traversal detection module 507.
[0145] The traversal detection module 507 is configured to determine whether the file name is traversed completely.
[0146] In this case, the traversal module 501 is further configured to continue to traverse the plurality of file names in the case that the traversal is not completed.
[0147] In some other embodiments, as shown, the database script deployment apparatus 500 further includes a character set detection module 508. Figure 5
[0148] The character set detection module 508 is configured to detect whether a type of a character set in the first database script to be deployed is a preset type.
[0149] In this case, the deployment module 504 is further configured to deploy the first database script to be deployed to the target database in the second server based on the first connection string information in the case that the type of the character set in the first database script to be deployed is the preset type.
[0150] The database script deployment apparatus 500 provided by the embodiments of the present application can perform the method shown in the above method embodiments, and the implementation principles and beneficial effects can refer to the related description in the method embodiments, which will not be repeated here.
[0151] Figure 6 A structural schematic diagram of a server provided by the embodiments of the present application is shown in FIG. 6. Figure 6 As shown, the server includes a memory 601, a transceiver 602 and at least one processor 603.
[0152] The transceiver 602 is configured to interact with other devices to realize the transceiving of data. For example, in the embodiments of the present application, the transceiver 602 can be specifically configured to connect with the second server, and is further configured to send the database script to be deployed to the second server to which the database script to be deployed is deployed.
[0153] The memory 601 is configured to store computer program codes, which include computer instructions. The computer instructions run in the above server to realize the method shown in the above method embodiments. For example, the memory can include a random access memory (RAM), and can also include a non-volatile memory (NVM), for example, at least one disk memory, and can also be a U disk, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0154] The processor 603 can be a general processor, including a central processing unit (CPU), a network processor (NP), etc.; can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component. The processor 603 can also be other general processors. The general processor can be a microprocessor or the processor can also be any conventional processor.
[0155] The memory 601, the transceiver 602 and the processor 603 are communicatively connected. For example, the memory 601, the transceiver 602 can be connected with the processor 603 through a system bus and complete mutual communication. The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, an industry standard architecture (ISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is shown in the figure, but it does not mean that there is only one bus or one type of bus.
[0156] Optionally, the memory 601 can be independent or integrated with the processor 603. When the memory 601 is independently arranged, the memory 601 and the processor 603 are connected through the system bus.
[0157] The embodiment of the present application further provides a chip for running instructions, which is used for executing the technical solutions of the database script deployment method in the above embodiment.
[0158] The embodiment of the present application further provides a computer readable storage medium, which stores computer instructions. When the computer instructions are executed by a processor, the technical solutions of the database script deployment method in the above embodiment are implemented. Specifically, when the computer instructions are executed by the processor, the server can execute the technical solutions of the database script deployment method in the above embodiment.
[0159] The embodiment of the present application further provides a computer program product, which comprises a computer program stored in a computer readable storage medium, at least one processor can read the computer program from the computer readable storage medium, and the at least one processor can implement the technical scheme of the database script deployment method in the above embodiment when executing the computer program.
[0160] The computer readable storage medium can be realized by any type of volatile or nonvolatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The computer readable storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0161] An exemplary computer readable storage medium is coupled to the processor, so that the processor can read information from the storage medium and write information to the computer readable storage medium. Of course, the computer readable storage medium can also be an integral part of the processor. The processor and the computer readable storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the computer readable storage medium can also exist as discrete components in an electronic control unit or a host device, and the embodiment of the present application does not limit this.
[0162] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the modules is only a logical function division, and actual implementation can have another division manner, for example, a plurality of modules can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed each other can be indirect coupling or communication connection through some interfaces, devices or modules, and can be electrical, mechanical or other forms.
[0163] The modules described as separate components may or may not be physically separate, and the components shown as modules may or may not be physical units, i.e., may be located in one place, or may be distributed to multiple network units. Part or all of the modules can be selected according to actual needs to implement the embodiments of the present application.
[0164] In addition, the functional modules in each embodiment of the present application can be integrated in one processing unit, or each module can be physically present alone, or two or more modules can be integrated in one unit. The unit formed by the above modules can be realized in the form of hardware or in the form of hardware plus software functional units.
[0165] The integrated modules realized in the form of software functional modules can be stored in a computer readable storage medium. The software functional modules stored in a storage medium include a plurality of instructions for causing a computer device (which can be a personal computer, a second server, or a network device, etc.) or a processor to execute part of the steps of the method of each embodiment of the present application.
[0166] It should be understood that the steps of the method disclosed in the embodiments of the present application can be directly embodied as hardware processor execution, or executed by a combination of hardware and software modules in the processor.
[0167] Those of ordinary skill in the art can understand that all or part of the steps of the above-mentioned method embodiments can be completed by program instruction-related hardware. The aforementioned program can be stored in a computer readable storage medium. The program, when executed, executes steps including the above-mentioned method embodiments; and the aforementioned storage medium includes ROM, RAM, magnetic or optical disc, and various media that can store program codes.
[0168] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements to part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A database script deployment method, characterized in that, Applied to a first server, the first server including multiple database scripts to be deployed, the first server being connected to a second server, the second server including a database, the method includes: Iterate through multiple file names, with each file name corresponding to a database script to be deployed; Extract the first index from the first file name currently traversed, where the first file name corresponds to the first database script to be deployed; Based on the first index, query the first connection string information of the first database script to be deployed; Based on the first connection string information, the first database script to be deployed is deployed to the target database in the second server.
2. The method according to claim 1, characterized in that, The first server includes multiple database scripts to be deployed, specifically: the first directory of the first server includes multiple database script files, and each database script file includes one database script to be deployed; Before traversing multiple file names, the method further includes: Read multiple database script files from the first directory and generate a filename list, the filename list including the multiple filenames; The traversal of multiple file names includes: Iterate through multiple file names in the list of file names.
3. The method according to claim 2, characterized in that, Before reading multiple database script files from the first directory and generating a list of filenames, the method further includes: Check if a database script file exists in the first directory.
4. The method according to any one of claims 1-3, characterized in that, The first server includes an array of connection string information; The step of querying the first connection string information of the first database script to be deployed based on the first index includes: The first connection string information is queried from the array based on the first index.
5. The method according to claim 4, characterized in that, The connection string information includes at least one of the following: server address, port number, database name, username, and user password; The array includes at least one of the following arrays: server address array, port number array, database name array, username data, and user password array.
6. The method according to any one of claims 1-3, characterized in that, After deploying the first database script to be deployed to the target database in the second server based on the first connection string information, the method further includes: Determine if the file names have been completely traversed; The traversal of multiple file names includes: Continue iterating through the multiple file names until the traversal is complete.
7. The method according to any one of claims 1-3, characterized in that, The method further includes: Check whether the character set type in the first database script to be deployed is a preset type; The step of deploying the first database script to be deployed to the target database in the second server based on the first connection string information includes: If the character set type in the first database script to be deployed is a preset type, the first database script to be deployed is deployed to the target database in the second server based on the first connection string information.
8. A database script deployment device, characterized in that, The apparatus is applied to a first server, which includes multiple database scripts to be deployed. The first server is connected to a second server, which includes a database. The apparatus includes: The traversal module is used to traverse multiple file names, with each file name corresponding to a database script to be deployed. The index extraction module is used to extract the first index from the first file name currently being traversed, where the first file name corresponds to the first database script to be deployed; The query module is used to query the first connection string information of the first database script to be deployed based on the first index; The deployment module is used to deploy the first database script to be deployed to the target database in the second server based on the first connection string information.
9. A server, characterized in that, include: A memory and at least one processor; the memory is communicatively connected to the processor; the memory is used to store computer program code, the computer program code including computer instructions; when the processor executes the computer instructions, it causes the server to perform the method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that, when executed by a processor, are used to implement the method as described in any one of claims 1-7.
11. A computer program product, characterized in that, When the computer program product is run on a computer / executed by the computer's processor, it implements the method as described in any one of claims 1-7.