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

Posted 乔小生1221

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql 数据库取出字段md5加密后形成新字段再插入相关的知识,希望对你有一定的参考价值。

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("
"):

        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+ "
")

最后插入表的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加密后形成新字段再插入的主要内容,如果未能解决你的问题,请参考以下文章

MYSQL数据库密码字段临时加密问题?

如何对sqlserver2005数据库中表字段进行加密,解密?

数据库如何实现字段加密

MySQL表中的密码字段类型问题

如何给MySQL数据库的表中的密码字段设置长度限制?

Laravel关联查询将一个字段中以逗号分隔的取出来形成新的字段