-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteDbFromDb10.py
55 lines (52 loc) · 1.48 KB
/
deleteDbFromDb10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
读取数据库,删除对应另库中数据
"""
import os
import xlrd
import re
import datetime
import pymysql
import csv
#数据库查询全部邮箱
def selectFromDb():
global selectDbTable
db = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='db3', charset='utf8')
cursor = db.cursor()
try:
sql = "SELECT EMAIL FROM " + selectDbTable
# 执行SQL语句
cursor.execute(sql)
# 获取所有记录列表
results = cursor.fetchall()
db.close()
return results
except Exception as err:
print('读取数据库出错',err)
#数据库删除数据
def delDb(data):
global dbTable
db = pymysql.connect(host='localhost', port=3306, user='root', passwd='', db='db3', charset='utf8')
cursor = db.cursor()
# print('data',data.__len__())
try:
for i in data:
sql = "DELETE FROM " + dbTable + " WHERE EMAIL = '{}'".format(i[0])
cursor.execute(sql)
db.commit()
except Exception as err:
print('删除错误',err)
#关闭数据库
db.close()
if __name__ == "__main__":
#待删除数据的表名
# dbTable = " EMAILTEST"
selectDbTable = "m11d8unsubscribe"
dbTable = " EMAILM11D8"
starttime = datetime.datetime.now()
#存错误信息文件
savePath = 'E:/pppresult/'
# 执行函数
data = selectFromDb()
delDb(data)
endtime = datetime.datetime.now()
print('运行时间:',endtime - starttime)