0

我正在使用PyMySQL-0.5.0并在将数据从文件加载到远程 MySQL 实例时面临一个模糊的错误/异常。在执行“加载数据本地 infile ...”语句时,我看到一个异常,上面写着:The used command is not allowed with this MySQL version.

任何线索,如果 PyMySQL 完全支持此操作(和/或其他版本是否支持此操作)

PS:

1) 错误详情:

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...' 支持/语法。

3)如果我使用mysql客户端,这个数据加载工作正常(即恕我直言,不应该有任何障碍——权限、特权、你有什么——这个加载):

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

3 回答 3

8

PYMySQL 确实支持LOAD DATA LOCAL INFILE,但您必须在数据库连接参数中启用它。例子:

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

默认设置为False

于 2016-11-15T22:24:06.940 回答
3

PyMySQLLOAD DATA LOCAL INFILE从 0.6.4 版开始支持

于 2015-07-27T18:44:42.093 回答
2

手册

如果LOAD DATA LOCAL在服务器或客户端中禁用,则尝试发出此类语句的客户端会收到以下错误消息:

错误 1148:此 MySQL 版本不允许使用的命令

PyMySQL 还不支持LOAD DATA LOCAL. 10 多个月以来,它一直是他们的错误跟踪器上的一个中等优先级缺陷,还没有人指派修复它,也没有设置里程碑。

请参阅此答案以了解如何改为LOAD DATA LOCAL使用 Python 的 MySQLdb 执行。

于 2012-05-17T15:53:07.137 回答