I am trying to load a csv file into the database but no success. The issue is that it works when I load the query directly in the mysql shell but it doesn't work when I tried doing from the python code. The code I am using is shown below:
db = connect_to_database()
cursor = db.cursor()
q = "LOAD DATA LOCAL INFILE '/home/ubuntu/load_file.csv' INTO TABLE test_load FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'"
db.query(q)
cursor.execute(q)
db.commit()
The error it throws says:
File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 281, in query
_mysql.connection.query(self, query)
_mysql_exceptions.OperationalError: (1148, 'The used command is not allowed with this MySQL version')
When I copied the string into the sql shell, it loads successfully. I'm not sure why its throwing this error.