sql循环生成数据 Posted on 2022-03-11 Edited on 2024-04-04 In Python Views: Symbols count in article: 552 Reading time ≈ 1 mins. 使用python脚本,批量生成mysql数据,并插入到服务器中 12345678910111213141516171819# 导入pymysql模块import pymysql# 连接databaseconn = pymysql.connect(host='ip', user='root', port=3306, password='admin', db='iod',charset='utf8mb4')# 得到一个可以执行SQL语句的光标对象cursor = conn.cursor()# 插入sqlsql = """INSERT INTO table(column1,column2...) VALUES (value1,value2,...);"""# 执行SQL语句,一次生成100W条太费时间,每1000条循环一次for k in range(1000): [cursor.execute(sql) for i in range(1000)] print("Done "+str(k))# 提交事务conn.commit()cursor.close()conn.close()