import pymysql import random conn = pymysql.connect(host ='127.0.0.1',user ='lick',passwd='123456',db='pythontest')#建立连接 print(conn) for i in range(1,10000): idm = random.randint(1000,10000) name = "test"+str(idm) cur = conn.cursor()#建立游标,以游标为基本执行sql语句 cur.execute("show tables")#执行sql语句 sql = "insert into tb01 values(%d,'%s');"%(idm,name) cur.execute(sql) cur.execute("select * from tb01") conn.commit()#提交sql语句到database ret = cur.fetchall()#获取语句执行的信息 print(ret) for x in ret: print(x) cur.close() conn.close()