python脚本如下,可直接复制如下脚本,进行更改数据库连接信息与查询SQL,其余信息均不变化。
#!/usr/bin/env python
# coding = UTF-8
#Author:Lucky,time:2023/3/7
import time
import pymysql # pip3 install PyMySQL
import threading
from time import ctime
from itertools import chain
threads_count = 75 # 并发线程数
def run_insert():
#此处填写数据库的相关连接信息
db = pymysql.connect(host="192.168.30.72", port=3001, user="root", passwd="Aa123456", db="tpch1t", charset="utf8")
cur = db.cursor()
sql ="select L_PARTKEY from LINEITEM where L_ORDERKEY=699959906;"
cur.execute(sql)
results = cur.fetchall() #获取全部的查询结果,默认是元组的打印方式
resultlist = list(chain.from_iterable(results)) #获取的结果用list方式打印
print("resultlist:",resultlist)
db.close() # 关闭连接
cur.close() #关闭游标
local_var = threading.local()
def Clean(args):
local_var.name = args
run_insert