2015-04-27 108 views
3

我試圖用LOAD LOCAL DATA INFILE和sqlalchemy將批處理文件上傳到我的服務器。我編輯了我的/etc/mysql/my.conf,在[mysql][mysqld]下包含local-infile == 1,但是當我運行該程序時,我得到了這個回溯。LOAD DATA LOCAL INFILE sqlalchemy和Python到mysql db

的代碼中的相關行是:

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)將允許我傳入本地infile參數。我無法在SQLAlchemy中找到等價物。任何幫助表示讚賞。

編輯:我一直在這一整晚,仍然沒有取得任何進展 - 很多死角。有任何想法嗎?

感謝,賈裏德

回答

6

您應該添加local_infile=1到連接字符串。

SQLALCHEMY_DATABASE_URI = "mysql://user:[email protected]/dbname?charset=utf8&local_infile=1"