码迷,mamicode.com
首页 > 数据库 > 详细

mysql 数据库取出字段md5加密后形成新字段再插入

时间:2020-01-13 16:04:51      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:with   http   青海   图片上传   str   data   com   index   部门   

INSERT INTO `permeationdomain` VALUES (10000.ys.51juban.com, 282, superman, 2020-01-06 08:54:28, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (5198.alog.com, 282, superman, 2020-01-06 08:54:28, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (51juban.com, 282, superman, 2020-01-06 08:54:28, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (admin.juban.com, 282, superman, 2020-01-03 11:06:05, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (alog.com, 282, superman, 2020-01-06 08:54:27, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (alogoms.cangyibao.com, 282, superman, 2020-01-06 08:54:27, null, null, null, null, null, null);

进行修改

# -*- coding: utf-8 -*-
import json
import codecs
import hashlib
from datetime import datetime

with open("permeationdomain.sql", "r",encoding= "utf-8") as f:
    flist = f.read()
    for i in flist.split("\n"):

        if i:
            everyone = i.split("VALUES")

            data = everyone[1][:-1]

            data = data.replace(null, "null")
            tupdata = eval(data)

            hashl = hashlib.md5()
            hashl.update(tupdata[0].encode("utf-8"))
            md5=hashl.hexdigest()
            listdata = list(tupdata)
            listdata.insert(0, md5)
            date = datetime.now()
            if listdata[4] == "null":
                listdata[4] = str(datetime.now())
            dataall = everyone[0] + "VALUES" + str(tuple(listdata)) + ";"

            with codecs.open("per.sql", "a", "utf-8") as f:
                f.write(dataall+ "\n")

最后插入表的sql语句

INSERT INTO `permeationdomain` VALUES (007cfbcec99a649d9e759c66be03e305, http://www.czdx.gov.cn/, 217001002, superman, 2019-12-18 09:09:19, null, 滁州市, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (0092ca6c575186e64ff53b477ee0d85b, http://www.bai.gov.cn/, 217001, superman, 2019-12-17 17:29:07, null, 北京, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (00b4509e1e3cb17dd5e2db7ce82d7e42, http://www.js.xinhuanet.com/, 051004, guozk, 2019-12-18 14:07:34, null, 江苏, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (00e17b3c96289daff5fa30967d20a4cc, test.alog.cc, 282, superman, 2020-01-06 08:53:30, null, null, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (00e6890bd2c99baaf5b556c6f97b2df0, http://www.ccps.gov.cn/bmpd/jsjxxy2/, 217, superman, 2019-12-17 16:49:23, null, 下设部门-全国党校(行政学院)教师进修学院, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (00eb8b07656ea5a3c362dc8e381b6d23, http://202.84.17.254/, 051007, guozk, 2020-01-06 11:07:32, null, 图片上传系统, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (022be146e00a5673b8b73c60a2b82e7a, https://wp.xinhua-news.cn/ssologin/, 051007, guozk, 2020-01-06 11:01:21, null, 新华社云存储登陆, null, null, null, null);
INSERT INTO `permeationdomain` VALUES (0292731fcab7e7004fc377d4d72a41ec, http://www.qhswdx.com/index.jsp, 217001, superman, 2019-12-17 17:29:07, null, 青海, null, null, null, null);

mysql 数据库取出字段md5加密后形成新字段再插入

标签:with   http   青海   图片上传   str   data   com   index   部门   

原文地址:https://www.cnblogs.com/qxh-beijing2016/p/12187357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!