程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python implements MySQL database to insert 100000 pieces of data

編輯:Python
# @Author : Kant
# @Time : 2022/1/22 16:37
'''
Insert 100000 pieces of data
'''
import pymysql
# Connect = connect = Connection = connections.Connection
connect_db=pymysql.Connect(host='localhost',port=3306,database='index_test',user='root',password='root',charset='utf8')
cur=connect_db.cursor()
# Turn on auto submit
connect_db.autocommit(True)
sql_str='''insert into test_index values(%s,%s)'''
# If Auto submit is enabled , The transaction needs to be opened , A transaction has been implicitly opened when the cursor object is created
# connect_db.begin()
n=0
for i in range(100000):
t = cur.execute(sql_str,[0,f'data_{i+1}'])
print(f' The first {i+1} Data inserted successfully ')
n+=t
print(f'{n} Data inserted successfully ...')
cur.close()
connect_db.close()


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved