Skip to content

Instantly share code, notes, and snippets.

@lxneng
Last active August 24, 2021 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lxneng/aabdc1d70eae367bfb4c9fb77adcde30 to your computer and use it in GitHub Desktop.
Save lxneng/aabdc1d70eae367bfb4c9fb77adcde30 to your computer and use it in GitHub Desktop.
Delete millions of rows from MySQL/TiDB
import os
import pymysql
if __name__ == '__main__':
ret = 1
conn = pymysql.connect(
host='tidb-cluster.dm',
port=4000,
user='dm',
password=os.getenv('DBPW'),
db='dm',
charset='utf8mb4',
autocommit=True)
with conn.cursor() as cur:
while ret:
ret = cur.execute("delete from <bigdatatable> where <conditions> limit 200000")
print(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment