Databases 10 min read

How to Recover Accidentally Deleted MySQL Databases: A Step‑by‑Step Guide

After a disastrous ERP data loss caused by a careless drop, this article walks through the importance of backups and provides a detailed, practical MySQL recovery process using full backups, binlog extraction, and incremental restoration to retrieve lost tables.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Recover Accidentally Deleted MySQL Databases: A Step‑by‑Step Guide

A Sad ERP Data Loss Story

During an ERP system upgrade, a third‑party developer asked for the SA password, later mistakenly initialized the database, wiping years of financial and supply‑chain data. The author spent three days in the server room restoring the lost data, highlighting the severe impact of missing backups.

MySQL Accidental Deletion Recovery Guide

Regular backups are essential; however, human error can still drop a database. The following procedure restores MySQL data using a nightly full backup and binary logs.

Recovery Workflow

Identify the full backup SQL file that contains a CHANGE MASTER statement and note the binlog file and position.

Export the relevant portion of the binlog with mysqlbinlog and remove any DROP statements.

Apply the full backup, then replay the cleaned binlog SQL to recover incremental changes.

Verify the restored tables and ensure the server is back to the state before the accidental drop.

Key Commands and Options

mysqldump -u root -p --all-databases --master-data=2 > full_backup.sql

(‑B database, ‑F flush logs, ‑R include routines, ‑‑master-data adds CHANGE MASTER).

Use

mysqlbinlog --start-position=… --stop-position=… binlog_file

to extract needed statements.

Before restoring, move the binlog out of the data directory to prevent new writes during recovery. After applying the full backup, replay the incremental SQL, omitting any harmful statements.

Finally, confirm that the target database (e.g., ops) exists and that all data between the backup and the drop has been restored.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

SQLmysqlBinlogDatabase RecoveryData loss
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

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.