# -*- coding: UTF-8 -*- # Author : LinYaoHong # Date : 2019/8/15 16:20 # Filename: 01-2-pymysql插入数据.py # Tools : PyCharm import pymysql, time conn = pymysql.connect(host='localhost', port=3306, user="root", password='111111', db="test") cursor = conn.cursor() # 游标 start_time = time.time() for i in range(10000): name = "lin" + str(i) gender = "男" email = "lin" + str(i) + "@qq.com" if i % 2 == 0: gender = "女" sql = "insert into user(name,gender,email) values(%s,%s,%s)" cursor.execute(sql, (name, gender, email)) conn.commit() cursor.close() conn.close() stop_time = time.time() print('run time is %s' % (stop_time-start_time))