How do you delete millions of rows safely?
Model answer
Delete in batches (DELETE ... LIMIT or by id ranges) with short transactions to avoid long locks and a huge transaction log. Consider partitioning and dropping old partitions, or TRUNCATE when removing everything. Run off-peak and monitor replication lag.
Learn this topic
INSERT, UPDATE and DELETE: Change Data Safely in the course SQL for Beginners: Learn Databases Step by Step.
Sign in to add your own answer.