0

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 |
+----------+

3 Answers 3

8

PYMySQL does support LOAD DATA LOCAL INFILE but you must enable it in the database connection parameters. Example:

connection = pymysql.connect(host='localhost', user='username', password='password', database='databasename', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor, local_infile=True)

The default is set to False.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. It worked for me after including local_infile=True
3

PyMySQL supports LOAD DATA LOCAL INFILE as of version 0.6.4

Comments

2

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.

1 Comment

Thanks for pointing out the bug. Guess PyMySQL is a no-go. Will likely just programmatically invoke mysql client. MySQLdb seems kind of a hassle - build dependencies and such. Would be great if PyMySQL would patch this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.