content_image/839763.jpg
Query OK, 8 rows affected (0.00 sec) Records: 8 Deleted: 0 Skipped: 0 Warnings: 0 

Here, we assume that person.xml  is located in the MySQL data directory. If the file cannot be found, the following error results: 

ERROR 2 (HY000): File ’/person.xml’ not found (Errcode: 2) 

The ROWS IDENTIFIED BY ’<person>’  clause means that each <person>  element in the XML file is considered equivalent to a row in the table into which the data is to be imported. In this case, this is the person  table in the test  database. 

As can be seen by the response from the server, 8 rows were imported into the test.person  table. This can be verified by a simple SELECT  statement: 

<img src='content_image/839763.jpg'>

This shows, as stated earlier in this section, that any or all of the 3 permitted XML formats may appear in a single file and be read using LOAD XML . 

The inverse of the import operation just shown—that is, dumping MySQL table data into an XML file—can be accomplished using the mysql  client from the system shell, as shown here: 

shell> mysql --xml -e "SELECT * FROM test.person" > person-dump.xml shell> cat person-dump.xml <?xml version="1.0"?> <resultset statement="SELECT * FROM test.person" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <row>  <field name="person_id">1</field>  <field name="fname">Kapek</field>  <field name="lname">Sainnouine</field> </row> <row>  <field name="person_id">2</field>  <field name="fname">Sajon</field>  <field name="lname">Rondela</field> </row> <row>  <field name="person_id">3</field>  <field name="fname">Likema</field>  <field name="lname">Örrtmons</field> </row> <row>  <field name="person_id">4</field>  <field name="fname">Slar</field>  <field name="lname">Manlanth</field> </row> 

