环境:
主机:10.0.1.120
数据库:mysql 5.6
查看数据结构
tail .sql
# csdn格式 LaoZheng # 670xxx # chengxxx@
awk '{print $1,$3,$5}' .sql > xxx.sql
# 过滤成3列
sql查询
desc sys_user; --查看表字段
SELECT max(CREATIONDATE) as endtime,username,email,password
FROM sys_user; -- 查看最后一条记录
创建表
CREATE TABLE `xxx_user` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(128) NOT NULL COMMENT '用户名',
`email` varchar(128) DEFAULT NULL COMMENT '邮箱',
`password` varchar(128) NOT NULL COMMENT '密码',
`phone` varchar(20) DEFAULT NULL COMMENT '手机号',
`certificate_code` varchar(32) DEFAULT NULL COMMENT '证件号',
`remark` varchar(256) DEFAULT NULL COMMENT '备注',
`gmt_create` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `index_username` (`username`),
KEY `index_email` (`email`),
KEY `index_phone` (`phone`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5;
-- PRIMARY 主键id
-- KEY 增加索引
-- AUTO_INCREMENT 自增id起始
INSERT INTO xxx_user (username,password,email) VALUES ("LaoZheng", "6702xxx","")
# 插入数据()
UPDATE sys_user SET remark = "来源千脑-06" -- 打个标签
py脚本导入到数据库
pip install pymysql # 安装数据库模块
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Author: LJ
Email: admin@attacker.club
Last Modified: -11-10 16:39:17
Description:
'''
'''
mxexx 809xxxx xxxx@
# 文件格式
'''
import pymysql
import datetime
starttime = datetime.datetime.now()
# 记录开始时间
conn = pymysql.connect(host='127.0.0.1',user='root',password='123456',port=3306,database="test")
cursor = conn.cursor()
# 使用cursor()方法获取操作游标;连接本地数据库,test库,test_user表
with open('/Users/X/Downloads/xxx.sql',encoding='utf-8') as f:
for row in f:
line = row.split()
try:
cursor.execute("""INSERT INTO test_user (username,
password,email)
VALUES ("%s","%s","%s");""" %(line[0],line[1],line[2]) )
mit() # 提交
except:
conn.rollback()
endtime = datetime.datetime.now()
print ("time: %s" % ((endtime - starttime).seconds))
cursor.close() # 关闭游标
conn.close() # 关闭连接