mysql-写入数据库

import pymysql

conn = pymysql.connect(host="localhost", port=3306, user="root", password="root", database="hello")

cursor = conn.cursor()
for i in range(1, 20):
    sql_r = "insert into ticket (sn,price,date) value ('{}','{}','{}')"
    sn = str(i)
    if len(sn) < 6:
        # 追加0前缀
        sn = "0" * (6 - len(sn)) + sn
    sql = sql_r.format(sn, 88 + i, "2022-02-18")

    cursor.execute(sql)

 

posted @ 2022-02-28 09:53  Gavin_j  阅读(65)  评论(0编辑  收藏  举报