由于测试中需要在数据库插入大量数据,进行页面展示的性能测试,以及下载功能的性能测试,所以这里想到使用Python造数据
代码如下
import pymysql
'''连接数据库,包括数据库ip、端口、用户名、密码、数据库'''
db = pymysql.connect(host='xx.xx.x.xx', user='xxx', password='cXX23456', port=xxx,
db='mv_flamionxx')
'''创建游标'''
cursor = db.cursor()
i = 1
id1 = 200000
while i <= 10:
sql = "INSERT INTO `mv_flame_recognition`.`flame_collection_verify`(`id`, `collection_id`, `converter_code`, `converter_num`, `is_verify`, `is_error`, `splash_type`, `splash_start_time`, `splash_end_time`, `gmt_create`, `gmt_modified`, `is_deleted`) VALUES (" + str(
id1) + ", 43, 'CVT01', 'LC039', b'0', b'1', 4, '2021-06-23 18:43:58', '2021-06-23 18:43:59', '2021-06-23 18:49:58', '2021-06-23 18:49:58', b'0')"
# values=(i,i)
cursor.execute(sql)
'''提交数据,必须提交,不然数据不会保存'''
db.commit()
id1 = id1 + 1
i = i + 1
print(id1)
print(i)
print("已经插入完成")
cursor.close()
db.close()
注意:
1)往数据库表插数时,有些字段可能不是char或者text格式的而是int时,会报错TypeError:must be str,not int。要在python里转成str
2)插入的sql语句,值是变量,需要用"++"