Databases 3 min read

Recovering Accidentally Deleted InnoDB .ibd Files Using Procfs File Handles

This article demonstrates how to recover mistakenly deleted InnoDB .ibd files by locating the open file handle through Linux procfs, locking database traffic, copying the hidden file, and restoring it to a running MySQL instance.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Recovering Accidentally Deleted InnoDB .ibd Files Using Procfs File Handles

The article presents an experiment where a script mistakenly deletes InnoDB .ibd files and shows how to recover them by tracing the open file handle via Linux procfs.

A test database is created (with innodb_file_per_table enabled for convenience), a workload is simulated, and then the corresponding table files are removed.

MySQL's open file handles are inspected, revealing the handle number (e.g., 54) associated with the deleted table, confirming that the file is still held by the server.

Recovery steps include locking database traffic (using offline_mode if supported), recording row counts and checksums, locating the hidden file through /proc/<pid>/fd/<handle> , copying it to a safe location, stopping MySQL, replacing the data file in the data directory, restarting the server, and verifying that the data is intact.

The underlying principle is that Linux only frees a file when its reference count drops to zero; while MySQL holds the file, it remains accessible via procfs even after being removed from the filesystem.

A thought question raises the issue of MySQL's buffer pool flushing during the copy process, asking whether this could cause data inconsistency.

LinuxInnoDBMySQLData recoveryFile Handlesprocfs
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.