python-mysql 批量造数据

import pymysql

db = pymysql.connect(
    host="124.70.xxx.xxx",
    user="root",
    password="3xxxx",
    database="novel"
)

mycursor = db.cursor()
phone = ( (phone,phone) for phone in range(13100110000,13100112000))

sql = "INSERT INTO `novel`.`user`( `username`, `password`, `nick_name`, `user_photo`, `user_sex`, `account_balance`, `status`, `create_time`, `update_time`) VALUES (%s, '25d55ad283aa400af464c76d713c07ad', %s, NULL, NULL, 0, 0, '2022-09-07 21:53:04', '2022-09-07 21:53:04');"
try:
    # 执行sql语句
    mycursor.executemany(sql,phone)
    # 提交到数据库执行
    db.commit()
except Exception as e:
    print(e)
    # 如果发生错误则回滚
    print("发生错误了")
    db.rollback()
posted @ 2022-09-22 00:02  我是小菜鸡丫丫  阅读(147)  评论(0编辑  收藏  举报