我正在尝试处理超过1GB的文本文件,并使用python将数据保存到Mysql数据库中.
我在下面粘贴了一些示例代码
import os
import MySQLdb as mdb
conn = mdb.connect(user='root', passwd='redhat', db='Xml_Data', host='localhost', charset="utf8")
file_path = "/home/local/user/Main/Module-1.0.4/file_processing/part-00000.txt"
file_open = open('part-00000','r')
for line in file_open:
    result_words = line.split('\t')
    query = "insert into PerformaceReport (campaignID, keywordID, keyword, avgPosition)"
    query += " VALUES (%s,%s,'%s',%s) " % (result_words[0],result_words[1],result_words[2],result_words[3])
    cursor = conn.cursor()
    cursor.execute( query )
    conn.commit()
实际上插入数据的列数超过18列,我刚刚粘贴了四列(例如)
因此,当我运行上面的代码时,执行时间需要一些 hours 
我所有的疑惑都是
编辑代码
query += " VALUES (%s,%s,'%s',%s) " % (int(result_words[0] if result_words[0] != '' else ''),int(result_words[2] if result_words[2] != '' else ''),result_words[3] if result_words[3] != '' else '',result_words[4] if result_words[4] != '' else '')
实际上我以上述格式提交值(通过检查结果存在)