0
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!

2 Answers 2

3

You forgot the space after INFILE and before INTO. Also make sure to sanitize infilename or risk SQL injections.

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

Comments

1

should be like this:

insertQuery = "LOAD DATA LOCAL INFILE " + infilename + " INTO TABLE vlan_area 
(vlan_id, area)"   

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.