將 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 版本不允許使用的指令

引用的內文件存在,我在運行命令之前選擇了一個資料庫,並且我對該資料庫具有適當的權限。資料庫表中的列名與 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

相關內容