我将尝试使用SQLAlchemy中的
LOAD LOCAL DATA INFILE
命令将批量文件上传至我的服务器。我已经编辑了/etc/mysql/my.conf
文件,并在[mysql]
和[mysqld]
下添加了local-infile==1
,但是当我运行程序时,出现了下面的错误信息。相关的代码行如下: Traceback (most recent call last):
File "main.py", line 48, in <module>
con.execute(sql)
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 906, in execute
return self._execute_text(object, multiparams, params)
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1054, in _execute_text
statement, parameters
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context
context)
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1332, in _handle_dbapi_exception
exc_info
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 199, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb)
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context
context)
File "/Users/eoddata/venv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute
cursor.execute(statement, parameters)
File "/Users/eoddata/venv/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/Users/eoddata/venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
sqlalchemy.exc.OperationalError: (_mysql_exceptions.OperationalError) (1148, 'The used command is not allowed with
this MySQL version') [SQL: "LOAD DATA LOCAL
INFILE 'stocks/AMEX_20150420.txt' INTO TABLE database.new_table\n
FIELDS TERMINATED BY ',' (Symbol,@Date,Open,High,Low,Close,Volume)\n
SET Date = STR_TO_DATE(@Date,'%%Y%%m%%d');"]
我通过文档进行了一些研究,但无法找到解决此错误的方法。使用python的MySQLdb(来自pip install MySQL-Python
)将允许我传递一个local-infile参数。我找不到SQLAlchemy中的等效方法。需要任何帮助。
编辑:我整夜都在解决这个问题,但仍然没有取得任何进展 - 很多死胡同。有什么想法吗?
谢谢,Jared