How to Recover a MySQL Database After Deleting Files or a Partition in Ubuntu: RAID 6 and LUKS2
Deleting files or an entire disk partition in Ubuntu can lead to critical data loss, especially if a MySQL database is running on the server. The situation becomes much more complicated when the storage system is built on a RAID 6 array and the data is additionally protected with LUKS2 encryption. In such conditions, standard recovery tools do not always produce the expected result, and careless actions may permanently destroy the information. In this article, we will review possible data loss scenarios, the specifics of working with RAID 6 and LUKS2, and the process of recovering a MySQL database after accidental deletion of files or a disk partition.

- Preparing the test environment and MySQL database
- Connecting the drives for analysis
- Recovering MySQL files from RAID 6 and LUKS2
- Restoring the database from an SQL dump
- Restoring MySQL tables from .ibd files
- Recovery results and limitations
- Frequently Asked Questions
- Comments
Hetman RAID Recovery 3.1 Unlimited Edition helps reconstruct RAID array structures, locate lost partitions, unlock LUKS2 if the password is available, and recover database files and SQL dumps.
We will demonstrate the program on a computer running Windows. However, Hetman RAID Recovery is also available for Linux and macOS.
How to Recover a Deleted MySQL Database on Linux RAID 6 + LUKS2 (Ubuntu)
Preparing the test environment and MySQL database
For testing, we used a Dell PowerEdge R710 server with a PERC H700 controller.
| Parameter | Specification |
|---|---|
| Server model | Dell PowerEdge R710 |
| RAID controller | Dell PERC H700 |
| Operating system | Ubuntu Server 24.04 |
| RAID | Linux MD RAID6; 4 SSD; 118.19 GiB |
| Block order / chunk size | Left Synchronous P+Q; 512 KiB |
| Offset, bytes | 34 603 008 B |
| GPT partitions | 3 × LUKS2 / ext4 |
| MySQL / InnoDB | 8.0.46 |
| Hetman RAID Recovery | 3.1 Unlimited Edition |
The PERC H700 exposed individual drives as single-disk RAID 0 volumes; four drives formed a software Linux MD RAID6 in Cockpit. Ubuntu Server 24.04 was installed on a separate drive.
A GPT partition table and three partitions with ext4 and LUKS2 encryption were created on the array; the second partition was 42 GB.


The mysql-data directory was placed on the third partition and contained data from the test company_db database, system files, and MySQL logs. MySQL version 8.0.46 was used.

The database itself contained the customers, products and orders tables, as well as a view, a stored procedure, and a function.

The database backup was created in MySQL Workbench as an SQL dump and saved in the mysql-backups directory.
Before testing, the mysql-data and mysql-backups directories were copied from the third partition to the second. Then the second partition was deleted through Cockpit, and the database files and SQL dump were deleted from the third partition using Shift+Delete, bypassing the Recycle Bin. This prepared two scenarios: recovering files from a deleted partition and recovering deleted files from a preserved partition.


Connecting the drives for analysis
In our case, the RAID 6 member disks were connected to a Windows computer through a USB docking station, and Hetman RAID Recovery was launched for analysis.
In addition to working with physical disks, the program supports analysis of full byte-by-byte disk images. Such images can be created directly in Hetman RAID Recovery using the Save Disk function and stored on another healthy drive.

This is especially useful if the disk is unstable, has bad sectors, or produces read errors. Creating an image preserves the readable data and allows the copy to be scanned later, reducing the number of repeated accesses to the problematic disk.
If the disks remain on the Linux server and are readable, they can be analyzed remotely. To do this, connect to the server via SSH in Hetman RAID Recovery and gain access to its block devices.
Recovering MySQL files from RAID 6 and LUKS2
STEP 1. Automatic detection of RAID 6 and LUKS partitions
Immediately after launch, Hetman RAID Recovery automatically detected the MD RAID 6 configuration and reconstructed its structure for analysis.

The right panel displays the array’s main parameters: RAID type and state, block order and size, as well as the list of participating disks with their sequence, offsets, and sizes.

On the assembled array, the program detected three partitions, including the previously deleted second one, and identified LUKS encryption on all three. Before entering the password, their file systems are not displayed — the partitions must be unlocked for further analysis.

STEP 2. Unlocking and recovering deleted files
To start the analysis, double-click the required partition. Since it is encrypted with LUKS2, the program will prompt you to enter a password or specify a key file. Enter the password and click Unlock.

First, select Fast Scan. Wait for the scan to complete, after which the program will open the structure of the found directories. In our test, the quick scan found the required files on the deleted partition.
If the required data is not found, run Full analysis and select Ext2/3/4 (Linux).

Review the scan results. In our case, the program displayed the SQL dump backup1.sql, the company_db directory, and the MySQL table files with the .ibd extension. The contents of the SQL dump can be checked in the preview window.

Select the files and folders you want to recover, then click Recovery. Choose a save method, specify another physical disk, and keep the option to restore the directory structure enabled.
Do not save the found files to the same drive from which they are being recovered, to avoid overwriting other lost data.

Restoring the database from an SQL dump
The simplest way to restore the database is to use the recovered SQL dump. It contains commands to create the database structure and restore the data as of the time the backup was made. If the appropriate export options were selected, the dump will also include views, procedures, and functions.
Launch MySQL Workbench and connect to the MySQL server. Open the Server — Data Import menu, select Import from Self-Contained File, and specify the recovered SQL file.

If the entire mysql-data directory with MySQL system files was lost, you must first restore the server’s functionality or prepare a new MySQL instance. Only then can the dump be imported through Workbench.
Select the target schema or create a new company_db database, then click Start Import. Wait for the operation to complete and check the log for errors.
Default Target Schema is used only if the dump does not specify its own schema. Before importing, review any CREATE DATABASE and USE statements in the dump to ensure that the data is imported into the intended test database.


Refresh the schema list. The database should now contain the customers, products, and orders tables. Open them and verify the records.

Restoring MySQL tables from .ibd files
If there is no suitable SQL dump, but Hetman RAID Recovery managed to recover the database directory with table files, you can attempt a physical recovery.
In our case, the company_db directory retained the customers.ibd, products.ibd, and orders.ibd files. Each of them contains the data and indexes of the corresponding InnoDB table.

Simply copying these files to the MySQL directory is not enough. The new server does not yet have definitions for the corresponding tables in the data dictionary. Therefore, recovery consists of two stages: first, you need to recreate the table structure, and then attach the recovered .ibd files to it.
Prepare a separate working MySQL instance of the same version, with innodb_file_per_table enabled and a compatible innodb_page_size. Work with copies of recovered files.

If the original SQL script with the structure is preserved, run the CREATE TABLE commands from it. The tables must exactly match the original ones, including column types, keys, indexes, character set (CHARACTER SET), collation (COLLATE), and row format. There is no need to run the data insertion commands — at this stage, the tables must remain empty.
Recovering table structure from .ibd files (if needed)
If the original SQL script is not available, you can attempt to recover the table structure from the .ibd files. In MySQL 8.0, they contain SDI — the data dictionary metadata. The ibd2sdi utility is used to read it.
Run it for each recovered file and save the results in JSON format. In our case, we obtained metadata from customers.ibd, products.ibd, and orders.ibd, and then used jq to inspect the definition of the customers table.
In a terminal, change to the directory containing copies of the recovered .ibd files. The file names and JSON output paths in these examples are relative to that directory.
ibd2sdi --type=1 --pretty --dump-file=customers.json customers.ibd
ibd2sdi --type=1 --pretty --dump-file=products.json products.ibd
ibd2sdi --type=1 --pretty --dump-file=orders.json orders.ibd

The metadata can include the table name, MySQL version, storage engine, collation, and tablespace parameters. It also contains the column definitions. Information about primary and unique keys, secondary indexes, and relationships with other tables is stored separately.
The resulting JSON can be analyzed manually in a text editor. Based on the detected parameters, special scripts and converters can automatically generate preliminary CREATE TABLE commands. For a large number of tables, this significantly speeds up structure recovery.
jq '.[] | objects | select(.type == 1) | .object.dd_object | {name, engine, collation_id, options, columns, indexes, foreign_keys}' customers.json

Importing recovered .ibd files
DISCARD TABLESPACE deletes the existing tablespace. Run it only on newly created empty tables on the target instance, never on the original database.
In Workbench, temporarily disable foreign key checks and execute the ALTER TABLE … DISCARD TABLESPACE command for each created table. This detaches the created empty tablespace and prepares the table for attaching the recovered file.
USE company_db;
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE customers DISCARD TABLESPACE;
ALTER TABLE products DISCARD TABLESPACE;
ALTER TABLE orders DISCARD TABLESPACE;

After that, copy the corresponding .ibd files to the database directory on the prepared server. After copying, do not forget to assign the mysql owner to the files and set the required access permissions.
The following commands illustrate the paths used in the test. Check the target MySQL data directory (SELECT @@datadir;) and adapt the paths. Run the commands only for the prepared empty tables; check file permissions after copying.
sudo cp -- '/srv/general-storage/Recovered files/company_db/customers.ibd' /var/lib/mysql/company_db/customers.ibd
sudo cp -- '/srv/general-storage/Recovered files/company_db/products.ibd' /var/lib/mysql/company_db/products.ibd
sudo cp -- '/srv/general-storage/Recovered files/company_db/orders.ibd' /var/lib/mysql/company_db/orders.ibd
sudo chown mysql:mysql /var/lib/mysql/company_db/customers.ibd /var/lib/mysql/company_db/products.ibd /var/lib/mysql/company_db/orders.ibd

In this test, importing the three .ibd files completed with InnoDB warning 1810. Without .cfg, MySQL skips schema verification; import only if the structure matches exactly. Import without .cfg can have undefined behavior for tables with columns added or dropped using ALGORITHM=INSTANT.
USE company_db;
SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE customers IMPORT TABLESPACE;
SHOW WARNINGS;
ALTER TABLE products IMPORT TABLESPACE;
SHOW WARNINGS;
ALTER TABLE orders IMPORT TABLESPACE;
SHOW WARNINGS;
SET FOREIGN_KEY_CHECKS=1;


Re-enabling FOREIGN_KEY_CHECKS does not validate previously imported rows. Check data and relationships separately. In our test SELECT returned 10 customers, 20 orders and 10 products.
USE company_db;
SELECT * FROM customers;
SELECT * FROM orders;
SELECT * FROM products;


The .ibd files make it possible to restore tables, their data, and indexes. However, views, procedures, and functions are not stored as separate files in the company_db directory. If they are not included in the SQL dump, these objects must be recreated manually.
After verifying the restored database, we recommend creating a new backup in SQL dump format.
Recovery results and limitations
Files were recovered successfully in both scenarios: partition deletion and file deletion. We imported the SQL dump and also restored three tables from .ibd files; verification queries returned 40 rows.
The recovered SQL dump can be imported through MySQL Workbench, restoring the database structure and data to the state at the time the backup was created. If no suitable dump is available, individual InnoDB tables may be recoverable from .ibd files by first recreating their structure.
Related experiments:







