gpt4 book ai didi

python - 加载数据本地 infile 在 Ubuntu 12.04 和 MySQL 中不起作用

转载 作者:行者123 更新时间:2023-11-29 02:01:25 24 4
gpt4 key购买 nike

使用 MySQL 我无法使用加载数据本地 infile 导入文件。我的服务器在 AWS RDS 上。这适用于 Ubuntu 10.04。我使用 apt-get install mysql-client 安装了客户端。如果我在 Python 中使用 mysqldb 或 mysql.connector,也会出现同样的错误。

  File "/usr/lib/pymodules/python2.7/mysql/connector/protocol.py", line 479, in cmd_query
return self.handle_cmd_result(self.conn.recv())
File "/usr/lib/pymodules/python2.7/mysql/connector/connection.py", line 179, in recv_plain
errors.raise_error(buf)
File "/usr/lib/pymodules/python2.7/mysql/connector/errors.py", line 82, in raise_error
raise get_mysql_exception(errno,errmsg)
mysql.connector.errors.NotSupportedError: 1148: The used command is not allowed with this MySQL version

我有很多数据要上传...我不敢相信 12.04 不受支持,我必须使用 12.04。

最佳答案

这不是真正的 python 问题...但总而言之,由 Ubuntu > 12.04 编译和分发的 mysql 不支持直接从 load data local infile 使用mysql 客户端。

如果您在 MySQL 引用文档中搜索错误 1148,请在上面链接的页面下方,在评论中:

Posted by Aaron Peterson on November 9 2005 4:35pm

With a defalut installation from FreeBSD ports, I had to use the command line mysql -u user -p --local-infile menagerie to start the mysql monitor, else the LOAD DATA LOCAL command failed with an error like the following:

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

...确实有效。

monte@oobun2:~$ mysql -h localhost -u monte -p monte --local-infile
Enter password:

...

mysql> LOAD DATA LOCAL INFILE 'pet.txt' INTO TABLE pet;
Query OK, 8 rows affected (0.04 sec)
Records: 8 Deleted: 0 Skipped: 0 Warnings: 0

mysql> SELECT * FROM pet;
+----------+--------+---------+------+------------+------------+
| name | owner | species | sex | birth | death |
+----------+--------+---------+------+------------+------------+
| Fluffy | Harold | cat | f | 1993-02-04 | NULL |
| Claws | Gwen | cat | m | 1994-03-17 | NULL |
| Buffy | Harold | dog | f | 1989-05-13 | NULL |
| Fang | Benny | dog | m | 1990-08-27 | NULL |
| Bowser | Diane | dog | m | 1979-08-31 | 1995-07-29 |
| Chirpy | Gwen | bird | f | 1998-09-11 | NULL |
| Whistler | Gwen | bird | NULL | 1997-12-09 | NULL |
| Slim | Benny | snake | m | 1996-04-29 | NULL |
| Puffball | Diane | hamster | f | 1999-03-30 | NULL |
+----------+--------+---------+------+------------+------------+
9 rows in set (0.00 sec)

mysql>

我一般不需要通过代码加载数据,所以这足以满足我的需求。如果您这样做,并且有能力/权限编辑您的 mysql 配置文件,那么相应部分中的 local-infile=1 行可能会更简单。

关于python - 加载数据本地 infile 在 Ubuntu 12.04 和 MySQL 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14011037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com