0
我加載一個名爲「rec.csv」我的MySQL數據庫文件在MySQL csv文件。我使用下面的代碼:問題批量加載使用Python
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()
由於某種原因它找不到該文件!我可以看到該文件存在,並在打印時正確打印它的路徑。但最終它會產生此錯誤:
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)")
[email protected]:~/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)")
有人可以告訴我,我做錯了什麼? 感謝