Problem bulk loading a csv file in Mysql using Python -
i loading file called 'rec.csv' mysql db. use 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" +"' table iens.recensies fields terminated ' ' lines terminated '\n' " db_cursor.execute(query) connection.commit()
for reason can't find file! can see file exists, , when print path printing correctly. in end generates 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 tell me, doing wrong? thanks
make slight change in load query.
load data local infile
i.e., add local in query.
as per mysql docs: if local specified, file read client program on client host , sent server. file can given full path name specify exact location. if given relative path name, name interpreted relative directory in client program started.
check link more information.
Comments
Post a Comment