首页 > 数据库技术 > 详细

往mysql插入大量迁移测试数据

时间:2020-08-20 18:19:01      阅读:105      评论:0      收藏:0      [点我收藏+]

 

 

CREATE TABLE userinfo
(
id varchar(10),
word varchar(10),
num int
)

 

python插入 

# -*- coding: utf-8 -*-
"""
Spyder 编辑器
"""

import random
import itertools as its
import random
import pymysql

def exec():
    
    db = pymysql.connect(host="192.168.122.8", port=30006, password="123456", user="root", 
                         database="ysp", charset="utf8")
    cursor = db.cursor()
    
    nums = "12345678901234567890123456"
    word = "abcdefghijklmnopqrstuvwxyz"
    r = its.product(word, repeat=5)
    s = its.product(nums, repeat=5)
    
    sql = "INSERT INTO userinfo(id, word, num) VALUES (%s, %s, %s);"
    for i in r:
        si = "".join(i)
        for j in s:
            sj = "".join(j)
            cur = random.randint(1, 100)
            cursor.execute(sql, [si, sj, cur])
            break;
    
    db.commit()
    cursor.close()
    db.close()
    
if __name__ == ‘__main__‘:
    exec()

  

往mysql插入大量迁移测试数据

原文:https://www.cnblogs.com/yspworld/p/13536408.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!