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

 

 

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插入大量迁移测试数据

上一篇:mysql优化: 内存表和临时表


下一篇:分布式数据库中间件 MyCat | 分库分表实践