我的new.csv文件
cat new.csv
;0;1;2;3;date
0;CHF;svájci frank;1;281,80;2017-06-15
1;EUR;euro;1;306,74;2017-06-15
2;USD;USA dollár;1;274,36;2017-06-15
3;AUD;ausztrál dollár;1;208,68;2017-06-15
4;BGN;bolgár Leva;1;156,84;2017-06-15
我想到了这个解决方案
db = MySQLdb.connect(host="localhost",user="milenko",passwd="newyork",db="dbase")
cur = db.cursor()
query = "LOAD DATA INFILE '/home/milenko/new.csv' INTO TABLE valami FIELDS TERMINATED BY ';' ENCLOSED BY '\"' ESCAPED BY '\\\\'"
cur.execute(query)
但现在我有问题
cur.execute(query)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/milenko/anaconda3/lib/python3.6/site-packages/MySQLdb/cursors.py", line 250, in execute
self.errorhandler(self, exc, value)
File "/home/milenko/anaconda3/lib/python3.6/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler
raise errorvalue
File "/home/milenko/anaconda3/lib/python3.6/site-packages/MySQLdb/cursors.py", line 247, in execute
res = self._query(query)
File "/home/milenko/anaconda3/lib/python3.6/site-packages/MySQLdb/cursors.py", line 411, in _query
rowcount = self._do_query(q)
File "/home/milenko/anaconda3/lib/python3.6/site-packages/MySQLdb/cursors.py", line 374, in _do_query
db.query(q)
如何解决这个问题?我检查了数据库(存在)。