2

I am trying to upload a file using MySQL LOAD DATA LOCAL INFILE function in Python.

In my load.py file, I have done:

import MySQLdb
conn = MySQLdb.connect(host, db_username, db_password, "Core_ver")
c = conn.cursor()
sql = """LOAD DATA LOCAL INFILE 'contact.out' INTO TABLE userinfo FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' (group_ID, rank_ID, login, password, first_name, last_name, email, contact_ID);"""
try:
  c.execute(sql)
  conn.commit()
except StandardError, e:
  print e
  conn.rollback()

Its not uploading anything. But I checked, the connection is working fine and the column names are also verified. What might have gone wrong?

aki2all
  • 379
  • 1
  • 6
  • 23
  • 1
    I bet this is it: http://stackoverflow.com/a/13154531/771848 – alecxe Aug 02 '13 at 19:31
  • @alecxe I have used `LOAD DATA LOCAL INFILE function` several times in Python before this, but never got any issues. Moreover, it doesn't print any error to debug. – aki2all Aug 02 '13 at 19:39
  • Well, also the behavior depends on [local_infile](http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_local_infile) mysql variable. Check it. – alecxe Aug 02 '13 at 19:42

1 Answers1

0

I had a foreign key constraint on the table Core_ver. But during performing LOAD DATA LOCAL INFILE function in python, I was not getting any errors, that's led to panic.

Anyways, the script is working fine. Thank Guys for the help.

aki2all
  • 379
  • 1
  • 6
  • 23