将 XML 导入 AWS RDS 实例

将 XML 导入 AWS RDS 实例

我正在尝试将一些 xml 加载到 AWS RDS(mySql)实例中。

XML 看起来像:(它是 ISO-3661 代码的 xml 转储)

<?xml version="1.0" encoding="UTF-8"?>
<countries>
  <countries name="Afghanistan" alpha-2="AF" alpha-3="AFG" country-code="004" iso_3166-2="ISO 3166-2:AF" region-code="142" sub-region-code="034"/>
  <countries name="Åland Islands" alpha-2="AX" alpha-3="ALA" country-code="248" iso_3166-2="ISO 3166-2:AX"  region-code="150" sub-region-code="154"/>
  <countries name="Albania" alpha-2="AL" alpha-3="ALB" country-code="008" iso_3166-2="ISO 3166-2:AL" region-code="150" sub-region-code="039"/>
  <countries name="Algeria" alpha-2="DZ" alpha-3="DZA" country-code="012" iso_3166-2="ISO 3166-2:DZ" region-code="002" sub-region-code="015"/>

我正在运行的命令是:

 LOAD XML LOCAL INFILE '/var/www/ISO-3166_SMS_Country_Codes.xml' INTO TABLE `ISO-3661-codes`(`name`,`alpha-2`,`alpha-3`,`country-code`,`region-code`,`sub-region-code`);

我收到的错误信息是:

错误 1148 (42000):所使用的命令不符合此 MySQL 版本要求

引用的 infile 存在,我在运行命令之前已选择数据库,并且我对该数据库拥有适当的权限。数据库表中的列名与 xml 字段名完全匹配。

答案1

这里有两件事。一个是服务器端,另一个是客户端。

在服务器(AWS RDS)上,检查您的参数组以确保local_infile设置为1。默认情况下,它在 RDSland 5.1 和 5.5 中启用。

其次,假设您正在使用 mysql 命令行,使用 local-infile 选项启动它:

mysql --local-infile -hhostname -uusername -p databasename

您也可以在 my.cnf 中设置 local-infile,尽管在这种情况下它与机器绑定;YMMV、IANAL、FSCK 等。

笔记本 5.1 文档说“默认情况下,二进制发行版中的所有 MySQL 客户端和库都使用 --enable-local-infile 选项进行编译,以兼容 MySQL 3.23.48 及之前版本。”至少最近的发行版似乎并非如此:

$ mysql --help | grep ^local-infile  # Ubuntu 12.04
local-infile                      FALSE
$ mysql --help | grep ^local-infile  # Ubuntu 12.04, fairly stock AWS AMI
local-infile                      FALSE
$ mysql --help | grep ^local-infile  # OSX 10.8
local-infile                      FALSE

相关内容