Skip to content

Instantly share code, notes, and snippets.

@diosmosis
Created April 4, 2012 21:39
Show Gist options
  • Save diosmosis/2305901 to your computer and use it in GitHub Desktop.
Save diosmosis/2305901 to your computer and use it in GitHub Desktop.
Deleting millions of rows from MySQL
import MySQLdb
rows_at_a_time = 100000
conn = # ...
cursor = conn.cursor()
while True:
cursor.execute("DELETE FROM mytable WHERE id < 2000000 LIMIT %d" % rows_at_a_time)
if cursor.rowcount < rows_at_a_time:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment