Recovering Deleted MySQL Data from Docker Volumes – Step‑by‑Step Guide
This guide walks through recovering a deleted MySQL database stored in Docker volumes by locating the mysql.ibd file, recreating a container with the same image, and mounting the original volume, allowing the lost data to be restored without a backup.
The author wanted to test MySQL gap locks, discovered an old MySQL container on a server, forgot its password, and removed the container with docker rm -f, only to realize a project still depends on that database.
Step 1 – Find the deleted container’s volume: Navigate to Docker’s volume directory, list volumes, and locate the mysql.ibd file that belongs to MySQL. Example commands:
# cd /var/lib/docker/volumes/
ll
find . -name mysql.ibdIdentify the correct volume by creation time and by inspecting its contents for the database name.
Step 2 – Launch a new container with the same image: Use the same MySQL image version to start a fresh container.
docker run -itd -p 3306:3306 -e MYSQL_ROOT_PASSWORD=xxxxxx mysql:8.0Step 3 – Attach the old volume to the new container: Inspect the new container to obtain its volume name, stop the container, replace its volume directory with the one found in Step 1, and restart the container.
# docker inspect <new_container_name>
# docker stop <new_container_name>
# cd /var/lib/docker/volumes/
# rm -rf <new_container_volume_name>
# cp -r <old_volume_path> <new_container_volume_name>
# docker start <new_container_name>After these actions the MySQL instance starts with the original data, effectively recovering the lost database.
Source: juejin.cn/post/7303785504004030515
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
