import random
import MySQLdb

def prepare_data():
    result = []
    type = ["a", "b", "c", "d", "e"]

    for i in range(50000):
        index = random.randint(0, 4)
        result.append((str(i), str(type[index]), str(i + 10), str(i)))
    return result

def insert_data():
    db = MySQLdb.connect(host='10.124.207.xxx',
                         user='xxxx',
                         passwd='xxxxx',
                         db='usecase',
                         charset='utf8')
    sql = 'INSERT INTO test_table ( name, type, phone, addr) VALUES ( %s, %s, %s, %s);'
    cur = db.cursor()
    cur.executemany(sql, prepare_data())
    db.commit()
    db.close()

if __name__ == '__main__':
    try:
        insert_data()
    except Exception as e:

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-26
  • 2021-08-06
  • 2022-12-23
  • 2021-11-18
  • 2022-01-21
猜你喜欢
  • 2022-12-23
  • 2022-02-20
  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案