简体   繁体   English

shell脚本将xml文件加载到mysql数据库中

[英]shell script to load xml file into mysql database

I have an xml file as: 我有一个xml文件:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<table name="abc">
<row>
<field name="year">2015</field>
<field name="copyright">Various</field>
<field name="review">Various</field>
</row>
<field name="year">2015</field>
<field name="copyright">Various</field>
<field name="review">Various</field>
<row>
<field name="year">2015</field>
<field name="copyright"/>
<field name="review"/>
</row>
</table>

The command for loading this xml file into mysql database is : 将此xml文件加载到mysql数据库的命令是:

LOAD XML LOCAL INFILE '/home/first.xml' INTO TABLE abc;

But this command is showing fields in database having proper closing tags. 但是此命令显示数据库中具有适当结束标记的字段。 In the third row copyright and review are having closing tags as /> So its showing entire row values as NULL even if year is having value as 2015 . 在第三行中,copyright和review的结束标记为/>因此即使year的值为2015其整个行的值也显示为NULL。 How this issue can be resolved any ideas?? 如何解决这个问题的任何想法?

I will give you two documents. 我会给你两个文件。 You should use both. 您应该同时使用。

  1. Using mysql in bash script 在bash脚本中使用mysql
  2. Load xml into MySQL 将xml载入MySQL

First connect to mysql from bash script and then run load xml command in that batch. 首先从bash脚本连接到mysql,然后在该批处理中运行load xml命令。

Using Java i replaced /> with ></field> . 我使用Java将/>替换为></field> So now the values are properly getting entered in db 因此,现在可以在db中正确输入值了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM