How import xml files with mysql LOAD XML LOCAL INFILE

后端 未结 2 1811
别跟我提以往
别跟我提以往 2020-12-11 06:25

I have a xml file like this:

test.xml



            


        
2条回答
  •  没有蜡笔的小新
    2020-12-11 06:54

    Include this line ROWS IDENTIFIED BY ''. with that your query should look like

    LOAD XML LOCAL INFILE "D:\\test.xml"
    INTO TABLE mytable
    ROWS IDENTIFIED BY '';
    

    Looks like your XML file formation is not correct and so even though 1 row gets inserted; all the values doesn't gets extracted (remains NULL).

    Do little changes as below

    Create table structure

    CREATE TABLE mytable (
    plugin_name varchar(255),
    title varchar(255),
    description varchar(255), 
    `file` varchar(255),
    `install` varchar(255),
    hook varchar(255),
    phrase varchar(255));
    

    Change your XML file

    
    
        Test
        some description
             test.tmp
        ![CDATA[
            global $test;
        ]]
            ![CDATA[
                global $local;
            ]]
            ![CDATA[Show categories]]
    
    

    Now if you use

    LOAD XML LOCAL INFILE "D:\\test.xml"
    INTO TABLE mytable
    ROWS IDENTIFIED BY '';
    

    All data gets extracted fine

    enter image description here

提交回复
热议问题