Someone accidentally ran DELETE without a WHERE clause on production. How do you recover?

IntermediateScenarioMySQL
Answer

Short answer

Stop the bleeding first (block further writes or take the app offline if needed), then recover the deleted rows with point-in-time recovery: restore the latest backup to a separate server, replay the binary logs up to just before the bad statement, and copy the missing rows back into production. Never restore directly over production in a panic.

Steps

  1. Find the exact time/position of the DELETE:
    mysqlbinlog --base64-output=decode-rows -v binlog.000245 | grep -n -B5 "DELETE FROM \`shop\`.\`orders\`" | head
    
  2. Restore the last full backup to a recovery instance (or on RDS: Restore to point in time → new instance, time = one second before the DELETE).
  3. Replay binlogs up to the position before the DELETE:
    mysqlbinlog --start-position=<backup pos> --stop-position=<pos before DELETE> binlog.000244 binlog.000245 | mysql -h recovery shop
    
  4. Export the lost rows from the recovery instance and insert them into production:
    mysqldump -h recovery --no-create-info --where="created_at < '2026-11-26 14:32'" shop orders > orders_restore.sql
    mysql -h prod shop < orders_restore.sql
    
  5. Verify row counts and check with the business.

Prevention

sql_safe_updates=1 for interactive sessions, no direct write access to prod for humans, changes reviewed and run inside transactions, delayed replicas, tested PITR.

What to say in the interview

"Contain the damage, then do point-in-time recovery to a separate instance — restore the backup and replay binlogs to just before the DELETE, or use RDS PITR — and copy the missing rows back. Afterwards, safe-updates mode and least-privilege access prevent a repeat."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MySQL basics

More on MySQL