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?

3
  • 1
    I bet this is it: stackoverflow.com/a/13154531/771848 Commented Aug 2, 2013 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. Commented Aug 2, 2013 at 19:39
  • Well, also the behavior depends on local_infile mysql variable. Check it. Commented Aug 2, 2013 at 19:42

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

I faced the same issue while working with mysql-connector-python. Adding the solution for that here,

conn = mysql.connect(host=HOST, database=DATABASE, user=USER, 
         password=PASSWORD,port = PORT,allow_local_infile=True)

Only after explicitly setting allow_local_infile=True the loading of csv file into the table is possible, despite the official documentation stating the value of the parameter being True by default. Refer this

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.