I am loading a file called 'rec.csv' to my Mysql DB. I use the code below:
import MySQLdb,os
path='testData'
absPath = os.path.abspath(path)
print absPath
conn = MySQLdb.connect(host='localhost',
user='root',
passwd='',
db='iens')
db_cursor = conn.cursor()
query = "LOAD DATA INFILE '"+ absPath + "/rec.csv" +"' INTO TABLE iens.recensies FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n' "
db_cursor.execute(query)
connection.commit()
For some reason it can't find the file! I can see the file exists, and the when print the path it is printing it correctly. but in the end it generates this error:
File "Load_Data.py", line 18, in <module>
db_cursor.execute(query)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.InternalError: (29, "File '/home/hossein/Documents/Parabots/DataBase/testData/rec.csv' not found (Errcode: 13)")
hossein@hossein-laptop:~/Documents/Parabots/DataBase$ python Load_Data.py
/home/hossein/Documents/Parabots/DataBase/testData
Traceback (most recent call last):
File "Load_Data.py", line 18, in <module>
db_cursor.execute(query)
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.InternalError: (29, "File '/home/hossein/Documents/Parabots/DataBase/testData/rec.csv' not found (Errcode: 13)")
Can someone tell me, what I am doing wrong? Thanks