CN114238270A - Database operation method and device, computer equipment and readable storage medium - Google Patents

Database operation method and device, computer equipment and readable storage medium Download PDF

Info

Publication number
CN114238270A
CN114238270A CN202111521344.3A CN202111521344A CN114238270A CN 114238270 A CN114238270 A CN 114238270A CN 202111521344 A CN202111521344 A CN 202111521344A CN 114238270 A CN114238270 A CN 114238270A
Authority
CN
China
Prior art keywords
script
database
target
execution
information
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111521344.3A
Other languages
Chinese (zh)
Inventor
吴永胜
涂勇
曹朝
王均
陈德虎
吴鹏成
何广辉
郭明月
白杰
季启文
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Pingan Payment Technology Service Co Ltd
Original Assignee
Pingan Payment Technology Service Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Pingan Payment Technology Service Co Ltd filed Critical Pingan Payment Technology Service Co Ltd
Priority to CN202111521344.3A priority Critical patent/CN114238270A/en
Publication of CN114238270A publication Critical patent/CN114238270A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0604Improving or facilitating administration, e.g. storage management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Human Computer Interaction (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the technical field of cloud storage, and discloses a database operation method, a database operation device, computer equipment and a readable storage medium, wherein the database operation method comprises the following steps: receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script; analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database; and running the target script to perform data operation on the data in the target library and obtain an operation result. The method and the device simplify the flow required by obtaining the database script, improve the efficiency of identifying and locking the target library by the user side, perform data operation on the data in the target library by directly operating the target script, and avoid the problem of low data operation efficiency caused by frequent access to different databases of different clusters.

Description

Database operation method and device, computer equipment and readable storage medium
Technical Field
The invention relates to the technical field of cloud storage, in particular to a database operation method and device, computer equipment and a readable storage medium.
Background
Currently, DDL and DML operations are performed in a database, generally, sql statements are written in the database to perform the DDL or DML operations, and if data is stored in a plurality of databases of a plurality of clusters in a distributed manner, a user is required to send a cluster name and an IP of the database which the user needs to operate first, then access the corresponding database according to the cluster name and the IP, and finally perform the DDL and DML operations by writing the sql statements in the database. The inventor realizes that the current database operation method enables a user to operate data in different databases of different clusters, needs to frequently access each database, and writes sql statements in the databases to complete the operation, which causes inconvenient operation for the user and causes low data operation efficiency.
Disclosure of Invention
The invention aims to provide a database operation method, a database operation device, computer equipment and a readable storage medium, which are used for solving the problems that in the prior art, in a plurality of databases of a plurality of clusters, a user needs to frequently access each database and write sql statements into the database, so that the operation of the user is inconvenient and the data operation efficiency is low.
In order to achieve the above object, the present invention provides a database operating method, applied in at least one cluster, where the cluster has at least one database, including:
receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database;
running the target script to perform data operation on the data in the target library and obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
In the foregoing solution, before receiving the execution request sent by the user side, the method further includes:
receiving a database script sent by an initiating terminal, carrying out naming operation on the database script to obtain a script name, and constructing a script library at least with one database script; the script name reflects attribute information of the database and the cluster where the database is located, and execution information and operation types of the database script.
In the foregoing solution, before receiving the execution request sent by the user side, the method further includes:
and constructing a script table with at least one script name, sending the script table to the user side, and displaying the script table on the user side in a click interface mode.
In the above scheme, the extracting the file path in the execution request includes:
identifying a path field or path character in the execution request;
and acquiring path information corresponding to the path field or the path character, and setting the path information as the file path.
In the foregoing solution, the parsing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database includes:
identifying attribute characters in the script name, and acquiring attribute information corresponding to the attribute characters, wherein the attribute information comprises a database type, a cluster name, a user name and a database name;
identifying operation characters in the script name, and acquiring an operation type corresponding to the operation characters, wherein the operation type refers to a file type of the database script;
identifying an execution character in the script name, and acquiring execution information corresponding to the execution character, wherein the execution information represents an execution influence line number, an execution time point, an execution sequence number and an execution number of the database script;
and summarizing the attribute information, the operation information and the execution information to form the script information.
In the foregoing solution, the running the target script to perform data operation on the data in the target library and obtain an operation result includes:
acquiring script information of the database script, and extracting execution information from the script information; extracting an execution sequence number, an execution library name and an execution number in the execution information, and loading the database script into an operation process in a database corresponding to the execution library name;
marking the database script through the execution serial number to serve as a unique identifier of the database script, and sequencing the database script in the running process according to the execution serial number to obtain a script sequence;
and executing the running process to sequentially execute the database scripts in the script sequence, so as to perform data operation on the target library corresponding to the database scripts and obtain an operation result.
In the above solution, after the running the target script to perform data operation on the data in the target library and obtain an operation result, the method further includes:
extracting the operation type of the script information; if the operation type is a definition operation, submitting the operation result to the target library; if the operation type is processing operation, extracting the execution influence line number in the script information, and judging whether the execution line number in the operation result is consistent with the execution influence line number; if the operation results are consistent, submitting the operation results to the target library; if the target script is inconsistent with the target script, performing rollback operation to restore the data in the target library to the state before the target script is operated; wherein, the defining operation refers to operating the target library and/or the carrier object in the target library, and the processing operation refers to operating the data in the carrier object;
and uploading the operation result to a block chain.
In order to achieve the above object, the present invention further provides a database operating apparatus, which is applied in at least one cluster, where the cluster has at least one database, and includes:
the script identification module is used for receiving an execution request sent by a user side and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
the analysis and identification module is used for analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information and setting the database as a target database;
the script running module is used for running the target script and performing data operation on the data in the target library to obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
To achieve the above object, the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor of the computer device implements the steps of the database operation method when executing the computer program.
To achieve the above object, the present invention further provides a computer-readable storage medium, which stores a computer program, and the computer program, when executed by a processor, implements the steps of the database operation method.
According to the database operation method, the database operation device, the computer equipment and the readable storage medium, the file path in the execution request is extracted, and the target script is directly obtained according to the file path, so that the flow required by obtaining the database script is simplified, and a user side can obtain the required database script without accessing a database. The script information is obtained by analyzing the script name of the target script, the database corresponding to the target script is identified according to the script information, the target library can be obtained only according to the script name, a user side does not need to access the target library, the user side does not need to input the cluster name, the user name and the database name of the target library to lock the target library, the efficiency of identifying and locking the target library by the user side is improved, and different data operations of a plurality of databases of a plurality of clusters are realized efficiently. By directly operating the target script, data operation corresponding to the target script can be performed on data in a target library which needs to be changed by a user side, and the user side does not need to access the target library which needs to be changed by the user side, and an operation result is obtained by a method of extracting and operating the database script in the target library, so that the user side needs to frequently access different databases of different clusters, and the problems of low data operation efficiency, high labor consumption of data operation and long time consumption are caused.
Drawings
FIG. 1 is a flow chart of a first embodiment of a database operation method according to the present invention;
FIG. 2 is a schematic diagram of an environment application of a database operation method according to a second embodiment of the database operation method of the present invention;
FIG. 3 is a flowchart of a specific method of database operation according to a second embodiment of the present invention;
FIG. 4 is a schematic diagram of program modules of a database operating apparatus according to a third embodiment of the present invention;
fig. 5 is a schematic diagram of a hardware structure of a computer device according to a fourth embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The invention provides a database operation method, a database operation device, computer equipment and a readable storage medium, which are suitable for the technical field of cloud storage and provide the database operation method based on a script identification module, an analysis identification module and a script operation module. The method comprises the steps of receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script; analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database; and running the target script to perform data operation on the data in the target library and obtain an operation result.
The first embodiment is as follows:
referring to fig. 1, a database operation method of this embodiment is applied to at least one cluster, where the cluster at least has one database, and includes:
s103: receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
s104: analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database;
s105: running the target script to perform data operation on the data in the target library and obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
In an exemplary embodiment, the file path in the execution request is extracted, and the target script is directly obtained according to the file path, so that the flow required for obtaining the database script is simplified, and the user side can obtain the required database script without accessing the database.
The script information is obtained by analyzing the script name of the target script, the database corresponding to the target script is identified according to the script information, the target library can be obtained only according to the script name, a user side does not need to access the target library, the user side does not need to input the cluster name, the user name and the database name of the target library to lock the target library, the efficiency of identifying and locking the target library by the user side is improved, and different data operations of a plurality of databases of a plurality of clusters are realized efficiently.
By directly operating the target script, data operation corresponding to the target script can be performed on data in a target library which needs to be changed by a user side, and the user side does not need to access the target library which needs to be changed by the user side, and an operation result is obtained by a method of extracting and operating the database script in the target library, so that the user side needs to frequently access different databases of different clusters, and the problems of low data operation efficiency, high labor consumption of data operation and long time consumption are caused.
Example two:
the embodiment is a specific application scenario of the first embodiment, and the method provided by the present invention can be more clearly and specifically explained through the embodiment.
The method provided by the present embodiment is specifically described below by taking an example that, in a server running a database operation method, a target script and a target library corresponding to the target script are identified, and the target script is run to perform data operation on data in the target library. It should be noted that the present embodiment is only exemplary, and does not limit the protection scope of the embodiments of the present invention.
Fig. 2 schematically shows an environment application diagram of a database operation method according to the second embodiment of the present application.
In an exemplary embodiment, the server 2 in which the database operation method is located is connected to the development end 3 and the user end 4 through a network; the server 2 may provide services via one or more networks, and the network 3 may include various network devices, such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and/or the like. The network 3 may include physical links, such as coaxial cable links, twisted pair cable links, fiber optic links, combinations thereof, and/or the like. The network may include wireless links, such as cellular links, satellite links, Wi-Fi links, and/or the like; the development end 3 and the user end 4 can be computer equipment such as a smart phone, a tablet computer, a notebook computer, a desktop computer and the like.
Fig. 3 is a flowchart of a specific method of operating a database according to an embodiment of the present invention, where the method specifically includes steps S201 to S206.
The method specifically comprises the following steps:
s201: receiving a database script sent by an initiating terminal, carrying out naming operation on the database script to obtain a script name, and constructing a script library at least with one database script; the script name reflects attribute information of the database and the cluster where the database is located, and execution information and operation types of the database script.
In order to ensure that a user side can directly obtain a database script without accessing the database and then obtain the database script, and the situation that the user side needs to frequently access each cluster and each database occurs, the step obtains the name of the script by naming the database script, and constructs the script library independent of the cluster and the database thereof in a manner of constructing the script library with the database script, and the database script has a unique address path in the script library, so that the user side does not need to frequently access the database of each cluster, and only needs to call the corresponding database script according to the requirement of the user side, and then subsequent data operation can be executed, the complicated flow of the current data operation is greatly simplified, and the data operation efficiency is improved.
Illustratively, the named format of the script name is:
dbtype _ cluttername _ datasensing _ SQLtype _ linenumber _ BEFORE _ SEQ _ UnifiedNumber _ Random _ DB _ execute, wherein,
dbtype is a database type, which is oracle or mysql;
a cluttername database instance characterizing cluster names and user names of the object database executed by the database script, such as: group1, user 2;
database names, which characterize the objects of execution of the database script, such as: jfxtedwxdataSQLtype file type, which characterizes the SQL language type of the database script, for example: characterizing the DDL defining the operation, and characterizing the DML processing the operation; wherein, the DDL (data definition language) is used for creating, modifying, deleting carrier objects (such as tables, views, stored procedures, triggers, indexes) in the database or database; a DML (data manipulation language) for adding, deleting, and modifying data in a table in a database;
the lineumber execution impact line number characterizes the code execution line number of the database script, for example: 10 lines;
a BEFORE execution time point, representing that execution is completed BEFORE a certain time point; for example: the execution is completed 2 points before each day: home _ OF _ DAY, 2;
SEQ execution sequence numbers, which characterize the execution order of a database script, for example: SEQ 1;
a unifieldenumber execution number, which represents a uniform execution number to which the database script belongs, for example: 302134, respectively;
random string randomly generated strings are used to ensure uniqueness of data scripts, for example: ojefdg;
DB execute, executing library name (DB), which characterizes the execution of the database script in this Database (DB), for example: a database named pafba.
If the database type of the database script is oracle, the database instance is group1user2, the database name is jfxtedwxdata, the file type is DDL, and the execution influence line number is 10 lines; completion needs to be performed 2 o' clock daily: home _ OF _ DAY, 2; the execution sequence number is SEQ1, the unified execution number is 302134, the randomly generated character string is ojefdg, and the execution library name is pafba; then, the script name will be obtained: oracle _ group1user2_ jfxtedwxdata _ DDL _10_ calenar _ hour _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql.
Based on the above example, the content of the database script is an sql statement, for example:
create database dearabao;
use dearabao;
create table niuzi(name varchar(20));
the database script is saved in a hello world directory OF a script library F, so that the path OF the file is F \ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _10_ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql.
In a preferred embodiment, the building at least one database script in the database and naming the database script to obtain a script name includes:
s11: receiving a script packet sent by an initiating terminal, and extracting attribute information and a database script in the script packet, wherein the attribute information describes a database type of a database script execution library name, a cluster name of a cluster where the database is located, and a database name and a user name of the database.
S12: and extracting the operation type and the execution information in the database script, wherein the operation type refers to the file type of the database script, and the execution information represents an execution influence line number, an execution time point, an execution sequence number and an execution number.
S13: and extracting the characters in the database script, and summarizing the characters to form character strings.
S14: and summarizing the attribute information, the operation type, the execution information and the character string to form a script name of the database script.
Specifically, a naming format of the script name is obtained, where the naming format is used to define the attribute information, the operation type, the execution information, and the rank of each field in the character string in the script name, where a first rank is a database type, that is: dbtype is; the second secondary database instance, namely: (iii) cluttername; the third bit is the database name, i.e.: databasename; the fourth bit is the file type, i.e.: SQLtype; the fifth bit is the number of execution impact rows, i.e.: lineumber; the sixth bit is the execution time point, i.e.: BEFORE; the seventh bit is the execution sequence number, i.e.: SEQ; the eighth bit is the execution number, i.e.: a Unified number; the ninth bit is a randomly generated character string, namely: random string; the tenth time is the execution library name, i.e.: DB execute; therefore, the database type, the database instance, the database name, the file type, the execution influence line number, the execution time point, the execution sequence number, the execution number, the character string and the execution library name are arranged according to the naming format to obtain the script name.
S202: and constructing a script table with at least one script name, sending the script table to the user side, and displaying the script table on the user side in a click interface mode.
In this step, the script table displayed in the form of the click interface is sent to the user side, so that the user side can conveniently select the required database script, the user side generates the execution request with the script name by selecting the script name in the click interface, and further the user side is not required to input the execution request with various characters, and the efficiency of selecting the database script by the user side is improved.
In this embodiment, a radio box and/or a check box corresponding to the script name is added before the script name, so that the user can select the required database script; or a drop-down box is arranged in the click interface, and the script name is recorded in the drop-down box, so that the technical effect of selecting the database script is realized by clicking the script name in the drop-down box by the user side.
S203: receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
in order to obtain the database script required by the user side without accessing the database, the step extracts the file path in the execution request and directly obtains the target script according to the file path, thereby simplifying the flow required for obtaining the database script.
In a preferred embodiment, the extracting the file path in the execution request includes:
s31: identifying a path field or path character in the execution request;
s32: and acquiring path information corresponding to the path field or the path character, and setting the path information as the file path.
Specifically, the execution request may be http request information, or may be a command line input by the user side in an sql command window;
if the execution request is http request information, for example: f: \\ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _10_ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql "; identifying a path field in the http request message by a preset regular expression, for example: "PATH"; extracting path information 'F: \ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _10_ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql' corresponding to the path field, and setting the path information 'F: \ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql' as the file path; wherein the regular expression is recorded with the path field.
If the execution request is the command line, < F, \\ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _10_ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql; identify address characters in the command line, such as: "<", the path information "F: \ hello world \ Oracle _ group1user2_ jfxtedwxdata _ DDL _10_ Calendar.HOUR _ OF _ DAY,2_ SEQ1_302134_ ojefdg _ pafba.sql" is obtained and set as the file path.
S204: and analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database.
In order to accurately execute the obtained database scripts in a target library, the script name of the target script is analyzed to obtain script information, the database corresponding to the target script is identified according to the script information, the target library can be obtained only according to the script name without accessing the target library by a user side, the target library is locked without inputting the cluster name, the user name and the database name of the target library by the user side, the efficiency of identifying and locking the target library by the user side is improved, and different data operations of a plurality of databases of a plurality of clusters are realized efficiently.
In a preferred embodiment, the parsing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database includes:
s41: identifying attribute characters in the script name, and acquiring attribute information corresponding to the attribute characters, wherein the attribute information comprises a database type, a cluster name, a user name and a database name;
s42: identifying operation characters in the script name, and acquiring an operation type corresponding to the operation characters, wherein the operation type refers to a file type of the database script;
s43: identifying an execution character in the script name, and acquiring execution information corresponding to the execution character, wherein the execution information represents an execution influence line number, an execution time point, an execution sequence number and an execution number of the database script.
S44: and summarizing the attribute information, the operation information and the execution information to form the script information.
Specifically, extracting fields of a first order, a second order and a third order in the script name, and summarizing to obtain the attribute information; extracting a field of a fourth order in the script name to obtain the operation type; extracting fields of a fifth order, a sixth order, a seventh order, an eighth order and a tenth order in the script name, and summarizing to obtain the execution information; and extracting a field of the ninth order in the script name to obtain the character string.
In a preferred embodiment, the identifying a database corresponding to the target script according to the script information, and setting the database as a target library includes:
s45: identifying a cluster corresponding to the cluster name in the script information, and setting a cluster corresponding to the database type in the cluster corresponding to the cluster name as a target cluster;
s46: and identifying a database corresponding to the user name in the script information in the target cluster, setting the database as a user database, and setting the user database corresponding to the database name in the script information as a target database.
It should be noted that, currently, a way of traversing each cluster and each database in each cluster is usually adopted to obtain the database corresponding to the database name, however, when the number of clusters and the number of databases in each cluster are very large, the problem of low efficiency of obtaining the target database due to traversing the database name will occur. In this embodiment, a manner of identifying a cluster corresponding to the cluster name in the script information and setting a cluster corresponding to the database type in the cluster corresponding to the cluster name as a target cluster is adopted, so as to accurately lock an applicable cluster of the database script; and accurately locking the target database by identifying the database corresponding to the user name in the script information in the target cluster, setting the database as a user database, and setting the user database corresponding to the database name in the script information as the target database. Therefore, for a script with a specific operation method, the step can accurately obtain the target library matched with the script in a large number of clusters and databases. And because the mode of obtaining the target library adopts the sequence of comparing the cluster name, the database type, the user name and the database name in sequence, each check only needs to consume less computing power, the required result can be quickly obtained, and the technical effects of reducing computing power consumption and improving the efficiency of obtaining the target library are realized through the mode of quickly checking and matching four times.
S205: running the target script to perform data operation on the data in the target library and obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
In this step, the data in the target library that needs to be changed at the user end can be subjected to the data operation corresponding to the target script by directly operating the target script, and the user end does not need to access the target library that needs to be changed at the user end, and the method for extracting and operating the database script in the target library obtains the operation result, so that the user end needs to frequently access different databases of different clusters, which causes the problems of low data operation efficiency, high labor consumption for data operation, and long time consumption.
In a preferred embodiment, the running the target script to perform data operation on the data in the target library and obtain an operation result includes:
s51: acquiring script information of the database script, and extracting execution information from the script information; and extracting an execution sequence number, an execution library name and an execution number in the execution information, and loading the database script into an operation process in a database corresponding to the execution library name.
In this step, a Process (Process) is a single operation of a program in a computer on a certain data set, is a basic unit for resource allocation and scheduling of a system, and is the basis of an operating system structure. The running process is a process preset in the database corresponding to the execution library name, and is used for allocating resources for the database script and executing the database script.
S52: marking the database script through the execution serial number to serve as a unique identifier of the database script, and sequencing the database script in the running process according to the execution serial number to obtain a script sequence;
in this step, the execution number is used for identifying the identity of the database script so that the user side and the development side can manage the database script in the running process; and the running process at least has one database script, and the database scripts are sequenced according to the execution sequence numbers so as to determine the sequence of the database scripts.
S53: and executing the running process to sequentially execute the database scripts in the script sequence, so as to perform data operation on the target library corresponding to the database scripts and obtain an operation result.
Further, if an error occurs in the execution process of the database script, a rollback operation is performed on the target library corresponding to the database script (for example, a rollback function is adopted), so that the target library, or the carrier object in the target library, or the data in the carrier object is restored to the state before the priority script is executed.
In a preferred embodiment, after the database scripts in the running process are sorted according to the execution sequence number to obtain a script sequence, the method further includes:
s54: extracting an execution time point in the execution information, calculating the time difference between the execution time point and the current time, and determining the priority of a database script in the script sequence according to the time difference; if the time difference is not greater than a preset time threshold, the priority is judged to be a first level, and if the time difference is greater than the time threshold, the priority is judged to be a second level;
in this step, the current time is obtained in real time by a preset time module (such as a clock function or a component), the time difference between the execution time point and the current time is calculated by a time module,
if the time difference is a negative value or zero, the current time is judged to exceed the execution time point, so that the database script corresponding to the execution time point is judged to be an expired script, and the expired script is deleted from the running process.
If the time difference is a positive value, judging whether the time difference is larger than the time threshold, if so, indicating that the database script corresponding to the time difference has longer residual running time, and therefore, setting the priority as a second level, and if not, indicating that the database script corresponding to the time difference does not have enough residual running time, and therefore, setting the priority as a first level.
S55: starting a priority branch process in the running process, setting a database script with a first priority as a priority script, and inputting the priority script into the priority branch process;
because the remaining running time of the database scripts at the first level is insufficient, in order to ensure that the database scripts can be completed before the execution time point, the priority branching process is started in the running process through the fork function, and the running priority of the priority branching process is prior to the running process, so that the database scripts in the priority branching process can be timely run.
S56: extracting a database script with attribute information consistent with the priority script in the script sequence, and setting the database script as an associated script; and recording the associated script into the priority branch process, arranging the priority script and the associated script in the priority branch process according to an execution sequence number, executing the priority branch process to run the priority script and the associated script, and performing data operation on a target library corresponding to the priority script and a target library corresponding to the associated script to obtain an operation result.
In this step, the execution condition of the priority script may be an operation result generated based on the pre-operation of another database script, so that the database script with the attribute information consistent with the priority script is used as the associated script, and the priority script and the associated script are sorted according to the execution sequence number to ensure that the priority script can be completely and correctly executed.
Further, if an error occurs in the execution process of the priority script, a rollback operation is performed on the target library corresponding to the priority script (for example, a rollback function is adopted), so that the target library, or the carrier object in the target library, or the data in the carrier object is restored to the state before the priority script is executed.
S206: extracting the operation type of the script information; if the operation type is a definition operation, submitting the operation result to the target library; if the operation type is processing operation, extracting the execution influence line number in the script information, and judging whether the execution line number in the operation result is consistent with the execution influence line number; if the operation results are consistent, submitting the operation results to the target library; if the target script is inconsistent with the target script, performing rollback operation to restore the data in the target library to the state before the target script is operated; the defining operation refers to the operation on the target library and/or the carrier object in the target library, and the processing operation refers to the operation on the data in the carrier object.
In this step, the execution line number of the database script recorded in the log information is obtained by accessing the log information generated by running the target script; the log information is generated by an operation process for operating the target script, the execution line number is a line number reflecting actual execution of the database script in the target library, and the execution line number is generated in the log information in real time in the process of operating the target script by the operation process. Wherein, the defining operation is a DDL (data definition language) for creating, modifying, deleting a database or a carrier object (e.g. table, view, stored procedure, trigger, index) in the database; the processing operation is a DML (data manipulation language) which is used for adding, deleting and modifying the data in the table in the database.
If the operation type is a defining operation (such as DDL), only corresponding operation is needed to be carried out on the target library and/or the carrier object, and the operation result is submitted to the target library through a commit function. If the operation type is processing operation (such as DML), judging whether the actual execution line number of the database script is consistent with the planned execution influence line number in the script information corresponding to the database script; if the operation data in the target library is inconsistent with the operation data in the target library, the operation data is generated, and the operation data is not submitted to the target library. And if the operation result is consistent with the operation result, submitting the operation result to the target library through a commit function.
In fig. 3, the S206 is shown by the following notation:
s206-1: extracting the operation type of the script information;
s206-2: if the operation type is a definition operation, submitting the operation result to the target library;
s206-3: if the operation type is processing operation, extracting the execution influence line number in the script information, and judging whether the execution line number in the operation result is consistent with the execution influence line number;
s206-4: if the operation results are consistent, submitting the operation results to the target library;
s206-5: if the target script is inconsistent with the target script, performing rollback operation to restore the data in the target library to the state before the target script is operated; the defining operation refers to the operation on the target library and/or the carrier object in the target library, and the processing operation refers to the operation on the data in the carrier object.
Further, the operation result is uploaded to a block chain.
It should be noted that the corresponding digest information is obtained based on the operation result, and specifically, the digest information is obtained by hashing the operation result, for example, by using the sha256s algorithm. Uploading summary information to the blockchain can ensure the safety and the fair transparency of the user. The user equipment can download the summary information from the blockchain so as to verify whether the operation result is tampered. The blockchain referred to in this example is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm, and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
Example three:
referring to fig. 4, a database operating apparatus 1 of the present embodiment is applied in at least one cluster, where the cluster at least has one database, and includes:
the script identification module 13 is configured to receive an execution request sent by a user side, and extract a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
the analysis and identification module 14 is configured to analyze the script name of the target script to obtain script information, identify a database corresponding to the target script according to the script information, and set the database as a target database;
the script running module 15 is configured to run the target script, so as to perform data operation on the data in the target library and obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
Optionally, the database operating apparatus 1 further includes:
the database construction module 11 is configured to receive a database script sent by an initiating terminal, perform naming operation on the database script to obtain a script name, and construct a script library having at least one database script; the script name reflects attribute information of the database and the cluster where the database is located, and execution information and operation types of the database script.
Optionally, the library building module 11 further includes:
the attribute extraction unit 111 is configured to receive a script packet sent by an originating terminal, and extract attribute information and a database script in the script packet, where the attribute information describes a database type of a database script execution library name, a cluster name of a cluster where the database is located, and a database name and a user name of the database.
An information extracting unit 112, configured to extract an operation type and execution information in the database script, where the operation type refers to a file type of the database script, and the execution information represents an execution line number, an execution time point, an execution sequence number, and an execution number.
And the character extraction unit 113 is used for extracting characters in the database script and summarizing the characters to form a character string.
And a name constructing unit 114, configured to summarize the attribute information, the operation type, the execution information, and the character string to form a script name of the database script.
Optionally, the database operating apparatus 1 further includes:
the table building module 12 is configured to build a script table with at least one script name, send the script table to the user side, and display the script table on the user side in a form of a click interface.
Optionally, the script identifying module 13 further includes:
a path identifying unit 131, configured to identify a path field or a path character in the execution request;
a path confirming unit 132, configured to acquire path information corresponding to the path field or the path character, and set the path information as the file path.
Optionally, the parsing and identifying module 14 further includes:
the attribute identification unit 141 is configured to identify an attribute character in the script name, and acquire attribute information corresponding to the attribute character, where the attribute information includes a database type, a cluster name, a user name, and a database name;
a type identifying unit 142, configured to identify an operation character in the script name, and obtain an operation type corresponding to the operation character, where the operation type is a file type of the database script;
an execution identification unit 143, configured to identify an execution character in the script name, and acquire execution information corresponding to the execution character, where the execution information represents an execution influence line number, an execution time point, an execution sequence number, and an execution number of the database script;
an information summarizing unit 144, configured to summarize the attribute information, the operation information, and the execution information to form the script information;
a cluster identification unit 145, configured to identify a cluster corresponding to the cluster name in the script information, and set, as a target cluster, a cluster corresponding to the database type in the cluster corresponding to the cluster name;
a library identification unit 146, configured to identify a database in the target cluster corresponding to the user name in the script information, set the database as a user database, and set a user database corresponding to the database name in the script information as a target library.
Optionally, the script running module 15 further includes:
a run preparation unit 151 configured to acquire script information of the database script and extract execution information from the script information; extracting an execution sequence number, an execution library name and an execution number in the execution information, and loading the database script into an operation process in a database corresponding to the execution library name;
a labeling and sorting unit 152, configured to label the database script through the execution serial number to serve as a unique identifier of the database script, and sort the database script in the running process according to the execution serial number to obtain a script sequence;
a process execution unit 153, configured to execute the running process, so as to sequentially execute the database scripts in the script sequence, and perform data operation on a target library corresponding to the database scripts and obtain an operation result;
a priority management unit 154, configured to extract an execution time point in the execution information, calculate a time difference between the execution time point and a current time, and determine a priority of a database script in the script sequence according to the time difference; if the time difference is not greater than a preset time threshold, the priority is judged to be a first level, and if the time difference is greater than the time threshold, the priority is judged to be a second level;
the priority preparation unit 155 is configured to start a priority branch process in the running process, set a database script with a first priority as a priority script, and enter the priority script into the priority branch process;
a priority execution unit 156, configured to extract a database script in which the attribute information in the script sequence is consistent with the priority script, and set the database script as an associated script; and recording the associated script into the priority branch process, arranging the priority script and the associated script in the priority branch process according to an execution sequence number, executing the priority branch process to run the priority script and the associated script, and performing data operation on a target library corresponding to the priority script and a target library corresponding to the associated script to obtain an operation result.
Optionally, the database operating apparatus 1 further includes:
an operation processing unit 16 for extracting an operation type of the script information; if the operation type is a definition operation, submitting the operation result to the target library; if the operation type is processing operation, extracting the execution influence line number in the script information, and judging whether the execution line number in the operation result is consistent with the execution influence line number; if the operation results are consistent, submitting the operation results to the target library; if the target script is inconsistent with the target script, performing rollback operation to restore the data in the target library to the state before the target script is operated; the defining operation refers to the operation on the target library and/or the carrier object in the target library, and the processing operation refers to the operation on the data in the carrier object.
The technical scheme can be applied to the technical field of cloud storage of cloud technology, a database script is obtained according to a file path in the execution request by extracting the file path, the database script is set as a target script, the script name of the target script is analyzed to obtain script information, a database corresponding to the target script is identified in a cluster for performing distributed storage on data according to the script information, the database is set as a target library, and the target script is operated to perform data operation on the data in the target library and obtain an operation result; the target script may be a computer script that performs data operations on the data based on metadata management techniques, including development of business vocabularies, definition of data elements and entities, business rules and algorithms, and data features.
Example four:
in order to achieve the above object, the present invention further provides a computer device 5, in which components of the database operating apparatus according to the third embodiment can be distributed in different computer devices, and the computer device 5 can be a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack-mounted server, a blade server, a tower server, or a rack-mounted server (including an independent server or a server cluster formed by multiple application servers) for executing programs. The computer device of the embodiment at least includes but is not limited to: a memory 51, a processor 52, which may be communicatively coupled to each other via a system bus, as shown in FIG. 5. It should be noted that fig. 5 only shows a computer device with components, but it should be understood that not all of the shown components are required to be implemented, and more or fewer components may be implemented instead.
In this embodiment, the memory 51 (i.e., a readable storage medium) includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the memory 51 may be an internal storage unit of the computer device, such as a hard disk or a memory of the computer device. In other embodiments, the memory 51 may be an external storage device of a computer device, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), or the like, provided on the computer device. Of course, the memory 51 may also include both internal and external storage devices of the computer device. In this embodiment, the memory 51 is generally used for storing an operating system and various application software installed in the computer device, such as program codes of the database operating device in the third embodiment. Further, the memory 51 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 52 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 52 is typically used to control the overall operation of the computer device. In this embodiment, the processor 52 is configured to execute the program codes stored in the memory 51 or process data, for example, execute the database operating device, so as to implement the database operating method of the first embodiment and the second embodiment.
Example five:
to achieve the above objects, the present invention also provides a computer readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application store, etc., on which a computer program is stored, which when executed by a processor 52, implements corresponding functions. The computer-readable storage medium of the present embodiment is used for storing a computer program for implementing the database operation method, and when executed by the processor 52, implements the database operation method of the first embodiment and the second embodiment.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for operating a database, applied in at least one cluster, the cluster having at least one database, the method comprising:
receiving an execution request sent by a user side, and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database;
running the target script to perform data operation on the data in the target library and obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
2. The database operation method according to claim 1, wherein before the receiving the execution request sent by the user side, the method further comprises:
receiving a database script sent by an initiating terminal, carrying out naming operation on the database script to obtain a script name, and constructing a script library at least with one database script; the script name reflects attribute information of the database and the cluster where the database is located, and execution information and operation types of the database script.
3. The database operation method according to claim 1, wherein before the receiving the execution request sent by the user side, the method further comprises:
and constructing a script table with at least one script name, sending the script table to the user side, and displaying the script table on the user side in a click interface mode.
4. The database operation method according to claim 1, wherein the extracting the file path in the execution request includes:
identifying a path field or path character in the execution request;
and acquiring path information corresponding to the path field or the path character, and setting the path information as the file path.
5. The database operation method according to claim 1, wherein the parsing a script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information, and setting the database as a target database includes:
identifying attribute characters in the script name, and acquiring attribute information corresponding to the attribute characters, wherein the attribute information comprises a database type, a cluster name, a user name and a database name;
identifying operation characters in the script name, and acquiring an operation type corresponding to the operation characters, wherein the operation type refers to a file type of the database script;
identifying an execution character in the script name, and acquiring execution information corresponding to the execution character, wherein the execution information represents an execution influence line number, an execution time point, an execution sequence number and an execution number of the database script;
and summarizing the attribute information, the operation information and the execution information to form the script information.
6. The database operation method according to claim 1, wherein the running the target script to perform data operation on the data in the target library and obtain an operation result comprises:
acquiring script information of the database script, and extracting execution information from the script information; extracting an execution sequence number, an execution library name and an execution number in the execution information, and loading the database script into an operation process in a database corresponding to the execution library name;
marking the database script through the execution serial number to serve as a unique identifier of the database script, and sequencing the database script in the running process according to the execution serial number to obtain a script sequence;
and executing the running process to sequentially execute the database scripts in the script sequence, so as to perform data operation on the target library corresponding to the database scripts and obtain an operation result.
7. The database operation method according to claim 1, wherein after the running of the target script for performing data operation on the data in the target library and obtaining the operation result, the method further comprises:
extracting the operation type of the script information; if the operation type is a definition operation, submitting the operation result to the target library; if the operation type is processing operation, extracting the execution influence line number in the script information, and judging whether the execution line number in the operation result is consistent with the execution influence line number; if the operation results are consistent, submitting the operation results to the target library; if the target script is inconsistent with the target script, performing rollback operation to restore the data in the target library to the state before the target script is operated; wherein, the defining operation refers to operating the target library and/or the carrier object in the target library, and the processing operation refers to operating the data in the carrier object;
and uploading the operation result to a block chain.
8. A database operating apparatus, applied in at least one cluster, the cluster having at least one database, comprising:
the script identification module is used for receiving an execution request sent by a user side and extracting a file path in the execution request; acquiring a database script according to the file path, and setting the database script as a target script;
the analysis and identification module is used for analyzing the script name of the target script to obtain script information, identifying a database corresponding to the target script according to the script information and setting the database as a target database;
the script running module is used for running the target script and performing data operation on the data in the target library to obtain an operation result; the data operation refers to an operation of adding, deleting and/or modifying the target library, or a carrier object in the target library, or data in the carrier object according to an sql statement in the database script, where the carrier object is a set used for storing data in the database.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the database operating method according to any of claims 1 to 7 are implemented by the processor of the computer device when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, the computer program stored in the computer-readable storage medium, when being executed by a processor, implementing the steps of the database operating method according to any one of claims 1 to 7.
CN202111521344.3A 2021-12-13 2021-12-13 Database operation method and device, computer equipment and readable storage medium Pending CN114238270A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111521344.3A CN114238270A (en) 2021-12-13 2021-12-13 Database operation method and device, computer equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111521344.3A CN114238270A (en) 2021-12-13 2021-12-13 Database operation method and device, computer equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN114238270A true CN114238270A (en) 2022-03-25

Family

ID=80755362

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111521344.3A Pending CN114238270A (en) 2021-12-13 2021-12-13 Database operation method and device, computer equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN114238270A (en)

Similar Documents

Publication Publication Date Title
CN114500690B (en) Interface data processing method and device, electronic equipment and storage medium
WO2019095667A1 (en) Database data collection method, application server, and computer readable storage medium
CN111737227A (en) Data modification method and system
CN112084179B (en) Data processing method, device, equipment and storage medium
CN112631924A (en) Automatic testing method and device, computer equipment and storage medium
CN113535677B (en) Data analysis query management method, device, computer equipment and storage medium
CN111625567A (en) Data model matching method, device, computer system and readable storage medium
CN113434506B (en) Data management and retrieval method, device, computer equipment and readable storage medium
WO2021174882A1 (en) Data fragment verification method, apparatus, computer device, and readable storage medium
CN115409507A (en) Block processing method, block processing device, computer equipment and storage medium
CN112364022A (en) Information derivation management method and device, computer equipment and readable storage medium
CN111951112A (en) Intelligent contract execution method based on block chain, terminal equipment and storage medium
CN115086047B (en) Interface authentication method and device, electronic equipment and storage medium
CN114238270A (en) Database operation method and device, computer equipment and readable storage medium
CN111460436B (en) Unstructured data operation method and system based on blockchain
CN114625751A (en) Data tracing query method and device based on block chain
CN114626352A (en) Report automatic generation method and device, computer equipment and storage medium
CN114003737A (en) Double-record examination assisting method, device, equipment and medium based on artificial intelligence
CN110704372B (en) Data recovery method and device
CN114143308A (en) File uploading information processing method and device, computer equipment and storage medium
CN113342647A (en) Test data generation method and device
CN113420050A (en) Data query management method and device, computer equipment and readable storage medium
CN112559546A (en) Database synchronization method and device, computer equipment and readable storage medium
CN115640170B (en) Big data synchronous backup and verification method
CN113434505B (en) Transaction information attribute retrieval method, device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination