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 |
+----------+
decimus phostle
  • 1,040
  • 2
  • 13
  • 28

3 Answers3

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
David Darby
  • 133
  • 3
  • 7
3

PyMySQL supports LOAD DATA LOCAL INFILE as of version 0.6.4

Stacey
  • 76
  • 3
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.

Community
  • 1
  • 1
eggyal
  • 122,705
  • 18
  • 212
  • 237
  • 1
    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. – decimus phostle May 17 '12 at 19:28