A method and device for recovering data in a damaged relational database
By obtaining the table structure and storage engine files to be recovered from a single storage engine file, and using slicing and analysis technology to recover data, the problem of rapid recovery of MySQL database in the case of corruption is solved, and the rapid recovery of corrupted database data is achieved.
Patent Information
- Application Number
- CN202011504395.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-18
- Publication Date
- 2025-02-18
- Estimated Expiration
- 2040-12-18
AI Technical Summary
In production environment, the MySQL database may be corrupted due to sudden power outage of the server, the mysqld process was killed while writing tables, and disk failures, and in an environment where logs are not recorded, users may be unable to recover the database data. .
A method and apparatus are provided that enables rapid recovery of data in a corrupt relational database from a single storage engine file. The method includes obtaining the table structure to be restored, obtaining the storage engine file according to the table structure, and recovering the data by slicing and analyzing.
By obtaining the table structure and storage engine files to be recovered, data in corrupted relational databases can be quickly recovered, solving the problem that database data cannot be recovered in an unrecorded log environment.
Smart Images

Figure CN112433878B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of databases, and in particular to a method and device for recovering data in a damaged relational database. Background Art
[0002] The MySQL database is one of the most widely used databases today. Since it is released as open source, it is used by many small and medium-sized businesses and is being used in popular web applications such as MediaWiki and Drupal.
[0003] In a production environment, the MySQL database may be damaged due to sudden power outages on the server, forced shutdown without shutting down the MySQL service first, the mysqld process being killed while writing a table, disk failure, etc. In an environment where logging is not performed, users may not be able to recover database data. Summary of the invention
[0004] Based on this, it is necessary to provide a method and device for recovering data in a damaged relational database in response to the above technical problems, which can quickly recover data in the damaged relational database from a single storage engine file.
[0005] In a first aspect, an embodiment of the present invention provides a method for recovering data in a damaged relational database, the method comprising:
[0006] Get the table structure to be restored;
[0007] Obtaining a storage engine file according to the table structure to be restored;
[0008] Restore data in a relational database according to the storage engine file and the table structure to be restored.
[0009] In some embodiments, obtaining a storage engine file according to the table structure to be restored includes:
[0010] Get the login command entered by the user;
[0011] Logging into a relational database according to the login instruction, the relational database including at least one table structure to be restored;
[0012] Get the input command entered by the user;
[0013] A storage engine file is searched in the relational database according to the input command.
[0014] In some embodiments, the restoring the data in the relational database according to the storage engine file and the table structure to be restored includes:
[0015] According to the data structure of the table structure to be restored and the data structure of the storage engine file, slicing and analyzing the data structure of the storage engine file to obtain data values of each field in the data structure of the table structure to be restored;
[0016] Creating a new table in the relational database according to the table structure to be restored;
[0017] Insert the data values into the new table.
[0018] In some embodiments, the storage engine file includes at least one piece of data, and the data includes:
[0019] A data start bit, a data end bit, at least one length flag bit, 25 bytes of unknown data bits and at least one data content bit, wherein the length flag bit, the 25 bytes of unknown data bits and the data content bits are located between the data start bit and the data end bit, and the length flag bit is used to indicate the length of the data segment in the data content bits.
[0020] In some embodiments, slicing and analyzing the data structure of the storage engine file according to the data structure of the table structure to be restored and the data structure of the storage engine file to obtain the data value of each field in the data structure of the table structure to be restored includes:
[0021] Acquire the total length of the data segment according to the data structure of the storage engine file;
[0022] Acquire the total length of the fields according to the data structure of the table structure to be restored;
[0023] Slicing is performed according to the total length of the data segment and the total length of the field to determine the data segment;
[0024] The data segment is analyzed to obtain data values of various fields in the data structure of the table structure to be restored.
[0025] In some embodiments, the step of obtaining the total length of the field according to the data structure of the table structure to be restored includes:
[0026] Get the length of the determined length field;
[0027] Calculating a length flag of the length-uncertain field according to the data structure of the table structure to be restored, wherein the length flag is used to indicate the length of the length-uncertain field;
[0028] The total length of the field is determined according to the length of the determined-length field and the length flag of the uncertain-length field.
[0029] In some embodiments, the analyzing the data segments to obtain data values of each data segment in the data structure of the table structure to be restored includes:
[0030] Get the field type and field length of each field in the data segment;
[0031] The data value of each field in the data structure of the table structure to be restored is obtained according to the field type and the field length.
[0032] In a second aspect, an embodiment of the present invention further provides a device for recovering data in a damaged relational database, wherein the device comprises:
[0033] A first acquisition module, used to acquire the table structure to be restored;
[0034] A second acquisition module is used to acquire a storage engine file according to the table structure to be restored;
[0035] The recovery module is used to recover the data in the relational database according to the storage engine file and the table structure to be recovered.
[0036] In a third aspect, an embodiment of the present invention further provides a server, including:
[0037] at least one processor; and,
[0038] a memory communicatively connected to the at least one processor; wherein,
[0039] The memory stores instructions that can be executed by the at least one processor, the instructions
[0040] The method is executed by the at least one processor so that the at least one processor can execute the above method for recovering data in a damaged relational database.
[0041] In a fourth aspect, an embodiment of the present invention further provides a non-volatile computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are executed by a processor, the processor executes the above-mentioned method for recovering data in a damaged relational database.
[0042] Compared with the prior art, the beneficial effects of the present invention are as follows: Different from the prior art, the method and device for recovering data in a damaged relational database in the embodiments of the present invention obtain the table structure to be recovered, then obtain the storage engine file according to the table structure to be recovered, and then recover the data in the relational database according to the storage engine file and the table structure to be recovered. For a damaged relational database, data can be quickly recovered as long as the table structure to be recovered and the corresponding storage engine file are known. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0044] Figure 1 It is a schematic diagram of the hardware structure of the server of the present invention;
[0045] Figure 2 is a flow chart of a method for recovering data in a damaged relational database in one embodiment of the present invention;
[0046] Figure 3a is a schematic diagram of a table structure to be restored in one embodiment of the present invention;
[0047] Figure 3b is a schematic diagram of the contents corresponding to the table structure to be restored in one embodiment of the present invention;
[0048] Figure 4 is the content of a data table to be restored in one embodiment of the present invention;
[0049] Figure 5 is a schematic diagram of a storage engine file in one embodiment of the present invention;
[0050] Figure 6 is a schematic diagram of a process for restoring data in a relational database in one embodiment of the present invention;
[0051] Figure 7 is a schematic diagram of a process for determining data values of each field in one embodiment of the present invention;
[0052] Figure 8 is a schematic diagram of specific contents of a data segment in one embodiment of the present invention;
[0053] Fig. 9 It is a schematic diagram of the structure of a device for recovering data in a damaged relational database in one embodiment of the present invention. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0055] It should be noted that, if there is no conflict, the various features in the embodiments of the present invention can be combined with each other, all within the scope of protection of the present invention. In addition, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order from the module division in the device or the flow chart. Furthermore, the words "first", "second", "third", etc. used in the present invention do not limit the data and execution order, but only distinguish the same items or similar items with basically the same functions and effects.
[0056] The embodiment of the present invention provides a server, see Figure 1 As shown, Figure 1 A hardware structure diagram of a server provided in an embodiment of the present invention, wherein the server 100 can be any type of device with computing capabilities.
[0057] Specifically, Figure 1 As shown, the server 100 includes one or more processors 102 and a memory 104 . Figure 1 A processor 102 is taken as an example. The processor 102 and the memory 104 may be connected via a bus or other means. Figure 1 The example of connecting through bus is taken in the following.
[0058] The memory 104, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as programs, instructions and modules corresponding to the method for recovering data in a damaged relational database in the embodiment of the present invention. The processor 102 executes various functional applications and data processing of the server by running the non-volatile software programs, instructions and modules stored in the memory 104, that is, implements the method for recovering data in a damaged relational database in the following embodiment.
[0059] The memory 104 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and application programs required for at least one function; the data storage area may store data created by using a device for recovering data in a damaged relational database, etc. In addition, the memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 104 may optionally include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the device for recovering data in a damaged relational database via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0060] like Figure 2 As shown, an embodiment of the present invention provides a method for recovering data in a damaged relational database, the method being executed by a server, and the method comprising:
[0061] Step 202: Obtain the table structure to be restored.
[0062] For example, the table structure to be restored is as follows: Figure 3a As shown, the table structure to be restored includes 7 fields, namely field a, field b, field c, field d, field e, field f and field g, wherein each field corresponds to a data type, for example, the data type corresponding to field a is varchar, the data type corresponding to field b is int, the data type corresponding to field c is longtext, the data type corresponding to field d is datetime, the data type corresponding to field e is varchar, the data type corresponding to field f is double, and the data type corresponding to field g is longtext. It should be noted that the lengths of some fields in the table structure to be restored are fixed, for example, the data type corresponding to field b is int, and the length of int is fixed to 4 bytes, so the length of field b is 4 bytes, the data type corresponding to field d is datetime, and the length of datetime is fixed to 5 bytes, so the length of field d is 5 bytes, similarly, the data type corresponding to field f is double, and the length of double is fixed to 8 bytes, so the length of field f is 8 bytes.
[0063] Among them, the content corresponding to the table structure to be restored is as follows Figure 3b As shown, the content corresponding to field a is alpha or ALPHA, the content corresponding to field b is 100 or 1000, the content corresponding to field c is charlie or CHARLIE, the content corresponding to field d is 2020-10-01 00:00:00 or 2020-10-01 00:00:01, the content corresponding to field e is echo or ECHO, the content corresponding to field f is 3.14 or 3.14159, and the content corresponding to field g is golf or GOLF.
[0064] Step 204: Obtain a storage engine file according to the table structure to be restored.
[0065] In the embodiment of the present invention, the table to be restored usually has multiple storage engine files, for example, Figure 4As shown, according to the different data sizes of the table to be recovered, the storage engine file includes at least one segment of data, and the data specifically includes a data start bit, a data end bit, at least one length flag bit, 25 bytes of unknown data bits and at least one data content bit, and the length flag bit, 25 bytes of unknown data bits and the data content bit are located between the data start bit and the data end bit, and the length flag bit is used to indicate the length of the data segment in the data content bit. Among them, the data start bit can be, for example, "supremum", and the data end bit can be, for example, "00 00 00 00 00 00 00 00". There is at least one data in the storage engine file that starts with "supremum" and ends with "00 00 00 00 00 00 00 00", and these data are the contents of the data table we need to recover.
[0066] In some of the embodiments, as an implementation of step 204, the method includes: obtaining a login instruction input by a user; logging into a relational database according to the login instruction, the relational database including at least one table structure to be restored; obtaining an input command input by the user; and searching for a storage engine file in the relational database according to the input command.
[0067] Specifically, the user logs in to the relational database, i.e., MySQL. Then, the server obtains the login instruction input by the user and logs in to the relational database according to the login instruction. Then, the server obtains the command input by the user, i.e., show variables like'%dir%'. The server finds the value corresponding to datadir in the relational database according to the input command, such as Figure 5 As shown in the figure, " / data / mysql" corresponding to datadir is the location of the storage engine file. After finding the storage engine file, open the storage engine file in hexadecimal format.
[0068] Step 206: Restore the data in the relational database according to the storage engine file and the table structure to be restored.
[0069] In the embodiment of the present invention, for a damaged relational database, namely a MySQL database, data in the relational database can be successfully restored as long as the table structure to be restored and the storage engine file corresponding to the table structure to be restored are known.
[0070] In an embodiment of the present invention, by obtaining a table structure to be restored, then obtaining a storage engine file according to the table structure to be restored, and then restoring data in a relational database according to the storage engine file and the table structure to be restored, for a damaged relational database, data can be quickly restored as long as the table structure to be restored and the corresponding storage engine file are known.
[0071] In some embodiments, as an implementation of step 206, Figure 6 As shown, the method includes:
[0072] Step 602: Slice and analyze the data structure of the storage engine file according to the data structure of the table structure to be restored and the data structure of the storage engine file to obtain data values of each field in the data structure of the table structure to be restored.
[0073] In the embodiment of the present invention, the data value of each field is determined after slicing and analysis.
[0074] In some embodiments, as an implementation of step 602, Figure 7 As shown, the method includes:
[0075] Step 702: Obtain the total length of the data segment according to the data structure of the storage engine file.
[0076] In an embodiment of the present invention, the total length of the data segment is the sum of the lengths of all data between the length marker and the data termination bit in the storage engine file.
[0077] Step 704, obtaining the total length of the fields according to the data structure of the table structure to be restored. Specifically, since the data structure of the table structure to be restored includes fields with a determined length and fields with an uncertain length, the length of the determined length fields is first obtained in the data structure of the table structure to be restored, and then the length flag of the uncertain length fields is calculated according to the data structure of the table structure to be restored. Specifically, there are 7 fields in the data structure of the table structure to be restored, among which the length of field b is known to be 4, the length of field d is known to be 5, and the length of field f is known to be 8. Specifically, by searching the data structure of the storage engine file, it is determined that the length flag of the uncertain length field in the data segment is 4 bytes. Then, the total length of the field is determined according to the length of the determined length field and the length flag of the uncertain length field.
[0078] Step 706, slicing is performed according to the total length of the data segment and the total length of the field to determine the data segment.
[0079] After obtaining the total length of the data segment and the total length of the field, slicing can be performed to obtain the data segment. For example, the total length of the data segment is 48, and there are a total of 3 fields in the table structure to be restored, and the 3 fields are all int type, and the int type is fixed to 4 bytes, so the total length of the 3 fields is 12 bytes, which means that the length of a data in the table structure to be restored is 12 bytes. It is also known that the total length of the data segment is 48 bytes, and the length of a data is 12 bytes, so the data segment can be sliced into 4 segments according to the length 12, so as to obtain 4 data, that is, 4 data segments.
[0080] Step 708: Analyze the data segment to obtain the data value of each field in the data structure of the table structure to be restored.
[0081] After the data segment is obtained, the data segment can be analyzed to obtain the data value of each field in the data structure to be restored. Specifically, the field type and field length of each field in the data segment are obtained, and the data value of each field in the data structure of the table structure to be restored is obtained according to the field type and field length. Figure 8 shown. Figure 8 It includes two data segments, the data start bit is supremum, the data end bit is 00 00 00, and the length flag is 04 04 07 05. The data segment is between the length flag and the data end bit. Among them, the type of field a in the data segment is varchar, and its corresponding length flag is 05. The length flag specifies the length of each field of indefinite length from back to front. The data value of field a is alpha when searching in the data segment of the storage engine file. Similarly, the type of field c in the data segment is longtext, and its corresponding length flag is 07. Then, the data value of field c is charlie when searching in the data segment of the storage engine file. The same is true for field e and field g. Field b, field d, and field f are known fields.
[0082] Step 604: Create a new table in the relational database according to the table structure to be restored.
[0083] Specifically, a new table is created by executing the statement CREATE TABLE sample(a varchar(255),b int(4),c longtext,d datetime,e varchar(255),f double,g longtext). The table is named sample and has seven fields a, b, c, d, e, f, and g, whose types are varchar, int, longtext, datetime, varchar, double, and longtext, respectively.
[0084] Step 606: insert the data value into the new table.
[0085] Data values can be inserted into a new table by executing SQL statements. Specifically, by executing INSERT INTO sample(a,b,c,d,e,f,g) VALUES('alpha',100,'charlie','2020-10-01 00:00:00','echo',3.14,'golf'); it can be understood as inserting data into the a, b, c, d, e, f, and g fields of the sample table, whose values are 'alpha', 100, 'charlie', '2020-10-01 00:00:00', 'echo', 3.14, 'golf' respectively. And execute INSERT INTO sample(a,b,c,d,e,f,g)VALUES('ALPHA',1000,'CHARLIE','2020-10-01 00:00:01','ECHO',3.14159,'GOLF'); it can be understood as inserting data into the a, b, c, d, e, f, and g fields of the sample table, whose values are 'ALPHA',1000,'CHARLIE','2020-10-01 00:00:01','ECHO',3.14159,'GOLF' respectively.
[0086] It should be noted that, in each of the above embodiments, there is not necessarily a certain order between the above steps. A person skilled in the art can understand, based on the description of the embodiments of the present invention, that in different embodiments, the above steps may have different execution orders, that is, they may be executed in parallel, may be executed interchangeably, and so on.
[0087] Accordingly, the embodiment of the present invention also provides a device 900 for recovering data in a damaged relational database, such as Fig. 9 As shown, including:
[0088] A first acquisition module 902 is used to acquire a table structure to be restored;
[0089] A second acquisition module 904 is used to acquire a storage engine file according to the table structure to be restored;
[0090] The recovery module 906 is used to recover the data in the relational database according to the storage engine file and the table structure to be recovered.
[0091] In an embodiment of the present invention, a table structure to be restored is acquired through a first acquisition module, and then a storage engine file is acquired according to the table structure to be restored through a second acquisition module. Then, data in a relational database is restored according to the storage engine file and the table structure to be restored through a recovery module. For a damaged relational database, data can be quickly restored as long as the table structure to be restored and the corresponding storage engine file are known.
[0092] Optionally, in other embodiments of the device, the second acquisition module 904 is specifically used for:
[0093] Get the login command entered by the user;
[0094] Logging into a relational database according to the login instruction, the relational database including at least one table structure to be restored;
[0095] Get the input command entered by the user;
[0096] A storage engine file is searched in the relational database according to the input command.
[0097] Optionally, in other embodiments of the device, the recovery module 906 is specifically used for:
[0098] According to the data structure of the table structure to be restored and the data structure of the storage engine file, slicing and analyzing the data structure of the storage engine file to obtain data values of each field in the data structure of the table structure to be restored;
[0099] Creating a new table in the relational database according to the table structure to be restored;
[0100] Insert the data values into the new table.
[0101] Acquire the total length of the data segment according to the data structure of the storage engine file;
[0102] Acquire the total length of the fields according to the data structure of the table structure to be restored;
[0103] Slicing is performed according to the total length of the data segment and the total length of the field to determine the data segment;
[0104] The data segment is analyzed to obtain data values of various fields in the data structure of the table structure to be restored.
[0105] Get the length of the determined length field;
[0106] Calculating a length flag of the length-uncertain field according to the data structure of the table structure to be restored, wherein the length flag is used to indicate the length of the length-uncertain field;
[0107] The total length of the field is determined according to the length of the determined-length field and the length flag of the uncertain-length field.
[0108] Get the field type and field length of each field in the data segment;
[0109] The data value of each field in the data structure of the table structure to be restored is obtained according to the field type and the field length.
[0110] Optionally, in other embodiments of the device, the storage engine file includes at least one segment of data, and the data includes: a data start bit, a data end bit, at least one length flag bit, 25 bytes of unknown data bits and at least one data content bit, and the length flag bit, 25 bytes of unknown data bits and the data content bit are located between the data start bit and the data end bit, and the length flag bit is used to indicate the length of the data segment in the data content bits.
[0111] It should be noted that the above-mentioned device for recovering data in a damaged relational database can execute the method for recovering data in a damaged relational database provided in the embodiment of the present invention, and has functional modules and beneficial effects for executing the application of the method. For technical details that are not fully described in the embodiment of the device for recovering data in a damaged relational database of the present invention, reference can be made to the method for recovering data in a damaged relational database provided in the embodiment of the present invention.
[0112] The server of the embodiment of the present invention exists in various forms, including but not limited to:
[0113] (1) Tower Server
[0114] A general tower server case is similar to the PC case we usually use, but a large tower case is much larger. In general, there is no fixed standard for the external dimensions.
[0115] (2) Rack-mounted servers
[0116] Rack-mounted servers are servers with a standard width of 19-inch racks, and the height ranges from 1U to several U, in order to meet the needs of dense deployment in enterprises. Placing servers on racks is not only conducive to daily maintenance and management, but also may avoid unexpected failures. First, placing servers does not take up too much space. Rack servers are neatly arranged in the rack, without wasting space. Secondly, connecting wires can also be neatly stored in the rack. Power cords and LAN cables can all be laid out in the cabinet, which can reduce the number of connecting wires piled on the ground, thereby preventing accidents such as kicking off the wires. The specified dimensions are the width (48.26cm = 19 inches) and height (multiples of 4.445cm) of the server. Since the width is 19 inches, racks that meet this requirement are sometimes called "19-inch racks."
[0117] (3) Blade Server
[0118] Blade server is a low-cost server platform with HAHD (High Availability High Density), which is specially designed for special application industries and high-density computer environments. Each "blade" is actually a system motherboard, similar to an independent server. In this mode, each motherboard runs its own system and serves different designated user groups, and there is no connection between them. However, these motherboards can be combined into a server cluster using system software. In cluster mode, all motherboards can be connected to provide a high-speed network environment, share resources, and serve the same user group.
[0119] (4) Cloud Server
[0120] Cloud server (Elastic Compute Service, ECS) is a simple, efficient, secure, reliable, and elastically scalable computing service. Its management method is simpler and more efficient than that of physical servers. Users can quickly create or release any number of cloud servers without having to purchase hardware in advance. The distributed storage of cloud servers is used to integrate a large number of servers into a supercomputer, providing a large amount of data storage and processing services. Distributed file systems and distributed databases allow access to common storage resources and achieve IO sharing of application data files. Virtual machines can break through the limitations of a single physical machine, and dynamic resource adjustment and allocation eliminate single points of failure of servers and storage devices to achieve high availability.
[0121] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0122] Through the description of the above implementation methods, ordinary technicians in this field can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Ordinary technicians in this field can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only disk, or a computer program.
[0123] Storage memory (Read-Only Memory, ROM) or random access memory (Random Access Memory, RAM), etc.
[0124] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Under the concept of the present invention, the technical features in the above embodiments or different embodiments may also be combined, the steps may be implemented in any order, and there are many other changes in different aspects of the present invention as described above, which are not provided in detail for the sake of simplicity. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they may still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for recovering data in a damaged relational database, characterized in that: The method comprises: Get the table structure to be restored; Obtaining a storage engine file according to the table structure to be restored; According to the data structure of the table structure to be restored and the data structure of the storage engine file, the data structure of the storage engine file is sliced and analyzed to obtain the total length of the required fields and data segments, so as to obtain the data value of each field in the data structure of the table structure to be restored; Creating a new table in the relational database according to the table structure to be restored; The data value is inserted into the new table to restore the table structure to be restored and the data in the relational database is restored.
2. The method according to claim 1, characterized in that The obtaining of the storage engine file according to the table structure to be restored includes: Get the login command entered by the user; Logging into a relational database according to the login instruction, the relational database including at least one table structure to be restored; Get the input command entered by the user; A storage engine file is searched in the relational database according to the input command.
3. The method according to claim 1, characterized in that The storage engine file includes at least one piece of data, and the data includes: A data start bit, a data end bit, at least one length flag bit, 25 bytes of unknown data bits and at least one data content bit, wherein the length flag bit, the 25 bytes of unknown data bits and the data content bits are located between the data start bit and the data end bit, and the length flag bit is used to indicate the length of the data segment in the data content bits.
4. The method according to claim 3, characterized in that According to the data structure of the table structure to be restored and the data structure of the storage engine file, slicing and analyzing the data structure of the storage engine file to obtain the total length of the required fields and data segments to obtain the data value of each field in the data structure of the table structure to be restored, including: Acquire the total length of the data segment according to the data structure of the storage engine file; Acquire the total length of the fields according to the data structure of the table structure to be restored; Slicing is performed according to the total length of the data segment and the total length of the field to determine the data segment; The data segment is analyzed to obtain data values of various fields in the data structure of the table structure to be restored.
5. The method according to claim 4, characterized in that The acquiring the total length of the fields according to the data structure of the table structure to be restored includes: Get the length of the determined length field; Calculating a length flag of the uncertain length field according to the data structure of the table structure to be restored, wherein the length flag is used to indicate the length of the uncertain length field; The total length of the field is determined according to the length of the determined-length field and the length flag of the uncertain-length field.
6. The method according to claim 5, characterized in that The step of analyzing the data segment to obtain the data value of each field in the data structure of the table structure to be restored includes: Get the field type and field length of each field in the data segment; The data value of each field in the data structure of the table structure to be restored is obtained according to the field type and the field length.
7. A device for recovering data in a damaged relational database, characterized in that: The device comprises: A first acquisition module, used to acquire the table structure to be restored; A second acquisition module is used to acquire a storage engine file according to the table structure to be restored; The recovery module slices and analyzes the data structure of the storage engine file according to the data structure of the table structure to be recovered and the data structure of the storage engine file, obtains the total length of the required fields and data segments, and obtains the data values of each field in the data structure of the table structure to be recovered; establishes a new table in the relational database according to the table structure to be recovered; inserts the data value into the new table to recover the table structure to be recovered and the data in the relational database.
8. A server, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
9. A non-volatile computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Fragment recovery method for MYSQL database
CN106897174A
Offline recovery method of deleted record on MYISAM storage engine and storage medium
CN108009049A