python
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import pymysql
import pymysql.cursors
import datetime
import time
def delData(min_id,max_id):
# 连接MySQL数据库
connection = pymysql.connect(host='192.168.3.XX', port=33XX, user='apps_new_w', password='BsMtABQi', db='userdata',charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
# 通过cursor创建游标
cursor = connection.cursor()
sql = "delete from `user_table` where id >= %s and id <= %s limit 10000"
print(sql)
# 执行数据查询
cursor.execute(sql,[min_id,max_id])
#查询数据库单条数据
connection.commit()
print(cursor.rowcount,"记录已删除")
# 关闭数据连接
connection.close()
return
minNum =1
maxNum =1612818680579782
limit = 10000000
cha = maxNum - minNum
rangeNum = int(cha/limit)
start = minNum
for i in range(rangeNum):
end = start + limit
print(start,end)
delData(start,end)
start = end
time.sleep(0.1)
-
一个问题是:SyntaxError: Non-ASCII character '\xe8' in file deleteMysql.py on line 9
-
pip install pymysql