python操作mysql批量插入数据(通过for循环方式)

import pymysql
conn =pymysql.connect(host='meixin-mysql-one.pre.cloud.db',user='video_adminu',passwd='ogEGcJq4RLOu',db='video_auction',port=5309,charset='utf8')
cur =conn.cursor()
count = 0
while count < 3:
    count += 1
    user_id = '19001995163'+str(count)
    user_nickname = user_id+'测试昵称'
    sql = 'INSERT INTO tbl_share_recode ( `user_id`, `invite_user_id`, `user_nickname`, `auction_id`, `goods_id`, `is_push`, `ctime`, `utime`) VALUES ("%s" , "100037460814","%s", "10577", "0", "0", "1541660745", "1541660745");'%(user_id,user_nickname)
    cur.execute(sql)
    conn.commit()
    print('数字'+str(count))
print("已经插入完成")
cur.close()
conn.close()

你可能感兴趣的:(Python,mysql,Python,mysql)