判断数据是否在数据库

"""
author:张鑫
date:2021/8/13 16:37
"""
import pymysql

# 即将插入的数据
url2 = ''
connect = pymysql.Connect(
    host='140.210.4.73',
    port=3306,
    user='twipad_cj',
    passwd='bj@#twipad_cj',
    db='tw_ipaddb',
    charset='utf8mb4'
)

cursor = connect.cursor()
# print('游标创建成功')
sql1 = 'select ir_md5 from hkby_facebookhistory_abroaddataall'
connect.ping(reconnect=True)
cursor.execute(sql1)
ir_md5_dec = cursor.fetchall()
ir_md5_dec=str(ir_md5_dec)
# 把需要查询的数据转变为元组neirong
ir_md5 = tuple([ir_md5], )
ir_md5 = ('("' + str(ir_md5) + '",)')
if ir_md5 in ir_md5_dec:

print('********************************************************数据已存在*******************************************************')

  

posted @ 2021-09-13 15:42  布都御魂  阅读(114)  评论(0)    收藏  举报