Search code examples
pythonmysqlmysql-pythonpython-db-api

PyMySQL error/exception on (file) data load to remote MySQL instance


I am using PyMySQL-0.5.0 and facing an obscure'ish error/exception when loading data from a file to a remote MySQL instance. Upon executing a 'load data local infile ...' statement, I am seeing an exception that says: The used command is not allowed with this MySQL version.

Any clues, if this operation is supported in PyMySQL at all(and/or if this is supported in some other version)

PS:

1) Error details:

2012-05-17 11:05:24,524 - 8988 - DEBUG - Loading table table_2012_05_16 
from file: /path/to/data/file_2012-05-16
2012-05-17 11:05:24,524 - 8988 - DEBUG - Executing update: load data local 
infile '/path/to/data/file_2012-05-16' into table table_2012_05_16(@dummy, c1, 
c2, c3, c4, c5, c6, c7);
2012-05-17 11:05:24,528 - 8988 - ERROR - Exception while executing update: 
<class 'pymysql.err.InternalError'> - (1148, u'The used command is not allowed 
with this MySQL version')

2) MySQL docs on the 'load data local infile...' support/syntax.

3) This data load works fine if I use the mysql client(i.e. IMHO there shouldn't be any impediments - permissions, privileges, what-have-you - to this load):

load_machine:~$ mysql -htarget_machine.baz -ufoo -pbar db -e "load data local 
infile '/path/to/data/file_2012-05-16' into table table_2012_05_16(@dummy, c1, 
c2, c3, c4, c5, c6, c7)"

load_machine: ~$ mysql -htarget_machine.baz -ufoo -pbar db -e "select count(*) 
from table_2012_05_16;"
+----------+
| count(*) |
+----------+
| 38563191 |
+----------+

Solution

  • From the manual:

    If LOAD DATA LOCAL is disabled, either in the server or the client, a client that attempts to issue such a statement receives the following error message:

    ERROR 1148: The used command is not allowed with this MySQL version

    PyMySQL does not yet support LOAD DATA LOCAL. It has been a medium-priority defect on their bug tracker for over 10 months, nobody yet assigned to fix it, no milestone set.

    See this answer for how to perform a LOAD DATA LOCAL using Python's MySQLdb instead.