def get(infilename):
fd_in = open(infilename, "r")
try:
con = mdb.connect (host=MY_HOST, user=MY_USER, passwd=MY_PASS, db=MY_DB)
cur = con.cursor()
insertQuery = "LOAD DATA LOCAL INFILE" + infilename + "INTO TABLE vlan_area (vlan_id, area)"
In python, I want to import a txt file to Mysql database, I want to get the file name dynamically, but this inserQuery is wrong, I don't know how to write it, can anyone help? many thanks!
asked Mar 6, 2012 at 13:16
manxing
3,33512 gold badges49 silver badges57 bronze badges
2 Answers 2
You forgot the space after INFILE and before INTO. Also make sure to sanitize infilename or risk SQL injections.
answered Mar 6, 2012 at 13:19
Kien Truong
11.4k2 gold badges34 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
should be like this:
insertQuery = "LOAD DATA LOCAL INFILE " + infilename + " INTO TABLE vlan_area
(vlan_id, area)"
answered Mar 6, 2012 at 13:24
Rahul
78.1k14 gold badges80 silver badges133 bronze badges
Comments
default