简体   繁体   中英

MySQL load data infile using Python not working

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM