Last active
August 24, 2021 03:22
-
-
Save lxneng/aabdc1d70eae367bfb4c9fb77adcde30 to your computer and use it in GitHub Desktop.
Delete millions of rows from MySQL/TiDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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