Bulk Insertion in MYSQL from XML Files

后端 未结 3 1823
轮回少年
轮回少年 2020-12-10 10:05

How can we load data to Mysql Tables from XML Files?? Is there any way to read data from XML Files and Write to MySql database.. I have a bulk of data in XML Files.

3条回答
  •  情歌与酒
    2020-12-10 10:31

    Try the LOAD XML function (MySQL 6.0). Here's the sample code from the reference manual:

    Using an XML document person.xml containing:

    
    
      
      
      MikaelRonström
      LarsThalmann
      5TomasUlin
      6MartinSköld
    
    

    you would create a table like so:

    CREATE TABLE person (
        person_id INT NOT NULL PRIMARY KEY,
        fname VARCHAR(40) NULL,
        lname VARCHAR(40) NULL,
        created TIMESTAMP
    );
    

    and use the following command to import the XML:

    LOAD XML LOCAL INFILE 'person.xml'
    INTO TABLE person
    ROWS IDENTIFIED BY '';
    

    Or if you're running MySQL 5.0 you can use LOAD_FILE to load the entire XML document as a string into a single column, and then parse it using MySQL's XPath functionality.

    This article on MySQL.com has more details: Using XML in MySQL 5.1 and 6.0.

提交回复
热议问题