数据库
首页 > 数据库> > mysql-写入数据库

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)

 

标签:数据库,mysql,写入,pymysql,cursor,sn,sql,len,conn
来源: https://www.cnblogs.com/gj0151/p/15944346.html