jmeter生成測試資料python指令碼

2021-09-29 19:16:09 字數 1644 閱讀 3515

#create table usertesting (id int ,username char(30),password char(30))建立usertesting**

#f讀取儲存此路徑的txt檔案,如果該路徑下該檔案不存在則建立新的

f = 『e:/jmeter_no_gui/user.txt』

#匯入mysql模組

import pymysql

#匯入時間模組

import time

#連線mysql資料庫

db = pymysql.connect(

host = 「192.168.3.169」,

port = 3306,

user = 「root」,

password = 「root」,

db = 「mammoworks_testing」)

#cursor當前的程式到資料之間連線管道

cursor = db.cursor()

organizationid = 10

usertype = 1

password = 『xqks4orxjfvvfj4wl4mmkg==』

createtime = time.strftime(』%y-%m-%d %h:%m:%s』,time.localtime(time.time()))

updatetime = time.strftime(』%y-%m-%d %h:%m:%s』,time.localtime(time.time()))

#要執行的sql語句,%s表示傳入的值以字串形式傳入,與資料庫字段型別無關

sql = 「insert into user (userid,username,password,mobile,createtime,updatetime,organizationid,usertype)values (%s,%s,%s,%s,%s,%s,%s,%s)」

#寫入方式開啟f檔案

with open(f, 『w』) as write_user:

username = 『name1』

userid = 1357217338980663

i = 1

mobile = 1357217338

#i生成5000條資料

print(『正在寫入資料。。。\n』)

while i <= 500:

username = 「name」 + str(i)

userid = userid + i

mobile = mobile + i

#f檔案中寫入組合後的username和password,writelines只接受乙個值,所以多個值需要組成乙個列表進行寫入

write_user.writelines([str(mobile),』,』,『123456』,』\n』])

#執行sql,傳值

cursor.execute(sql,(userid,username,password,mobile,createtime,updatetime,organizationid,usertype))

#提交事務

db.commit()

i = i + 1

print(『寫入完畢』)

#關閉游標

cursor.close()

#關閉資料庫連線

db.close()

測試資料生成

目的 sql server 搭建日誌傳輸,模擬災難轉移,在主庫上不斷生成測試資料,模擬生產環境。生成測試資料指令碼 表結構 if table dbo.t1 exists,then drop it if object id dbo.t1 u is not null drop table dbo.t1 ...

快速生成測試資料

select rownum as id,to char sysdate rownum 24 3600,yyyy mm dd hh24 mi ss as inc datetime,trunc dbms random.value 0,100 as random id,dbms random.string...

postgresql 生成測試資料

此處,我簡單的寫乙個例子,供參考 在postgresql9.1下面做的 1 準備知識 針對 postgres生成資料方法 生成序列 select from generate series 1,5 生成date select date generate series now now 1 week 1 ...