#coding=utf-8
import MySQLdb

db = MySQLdb.connect("IP","用户名","密码","库名",charset = 'utf8')
cursor = db.cursor()

f = open("文件名.txt", "r")
i = 1000000001
for eachline in f:
    sql = "INSERT INTO 表名(id, quanwen) VALUES (%d, \'%s\')" % (i, eachline)
    try:
       # 执行sql语句
       cursor.execute(sql)
       # 提交到数据库执行
       db.commit()
       i += 1
    except:
       # Rollback in case there is any error
       db.rollback()

# 关闭数据库连接
db.close()
f.close()

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-25
  • 2021-05-31
  • 2021-10-16
  • 2021-12-11
  • 2021-10-26
猜你喜欢
  • 2022-12-23
  • 2021-09-24
  • 2021-11-01
  • 2022-12-23
  • 2021-08-09
  • 2021-09-14
  • 2022-12-23
相关资源
相似解决方案