import pymysql import pandas as pd import uuid import datetime import random conn = pymysql.connect( host = '127.0.0.1', user = 'root', password = '123456', db = 'crm_info', port = 3306, charset = 'utf8' ) cur = conn.cursor() #创建游标 for i in range(1,30): id_ = uuid.uuid1().hex price = round(random.uniform(2000, 9000),2) ht_date = datetime.date.today() sql = "insert into ht_htxx values('{}','58401754b2ed11eaba23005056c00001','{}','增值服务','{}')".format(id_,ht_date,price) cur.execute(sql) #执行返回的是影响的行数 print(sql) conn.commit() #插入,更新,删除都需要做提交才会生效 #使用完之后需要关掉游标和数据库连接 cur.close() conn.close()
结果: