import hashlib
import pymysql
# sqlcreate = """CREATE TABLE md5 (
# ID BIGINT NOT NULL,
# MD5 CHAR(128) )"""
# sqlinsert = """INSERT INTO md5(ID,
# MD5)
# VALUES (96, 'b0f2a038c3be5306dafa596156b8b359')"""
m = hashlib.md5()
db=pymysql.connect("ip","数据库名","数据库密码","数据库表名")
for i in range(1,1000000):
cursor=db.cursor()
m.update(str(i).encode(encoding='UTF-8'))
sqlinsert1 = """INSERT INTO md5(ID,
MD5)
VALUES ({id_}, '{md5_}')""".format(id_=i ,md5_= m.hexdigest())
try:
cursor.execute(sqlinsert1)
print(str(i)+",")
db.commit()
except:
db.rollback()
db.close()
声明:
本文采用
BY-NC-SA
协议进行授权,如无注明均为原创,转载请注明转自
走着的小站
本文地址: python操作mysql数据库,写入MD5
本文地址: python操作mysql数据库,写入MD5