Gunakan option --xml, option ini berlaku untuk client mysql dan mysqldump. Dengan fungsi ini hasil query akan ditampilkan dengan format XML. Berikut Contohnya dan hasilnya:
Sedangkan jika tidak menggunakan Option --xml hasilnya:shell> mysql -uroot -e "SHOW VARIABLES LIKE '%version%'" --xml
<?xml version="1.0"?>
<resultset statement="SHOW VARIABLES LIKE '%version%'" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><row> <field name="Variable_name">protocol_version</field> <field name="Value">10</field> </row>
<row><field name="Variable_name">version</field> <field name="Value">5.1.22-beta-debug</field> </row>
<row><field name="Variable_name">version_comment</field> <field name="Value">Source distribution</field> </row>
<row>
<field name="Variable_name">version_compile_machine</field> <field name="Value">x86_64</field> </row>
<row><field name="Variable_name">version_compile_os</field> <field name="Value">suse-linux-gnu</field> </row> </resultset>
shell>mysql -uroot -e "SHOW VARIABLES LIKE '%version%'"
+-------------------------+---------------------+ | Variable_name | Value | +-------------------------+---------------------+ | protocol_version | 10 | | version | 5.1.22-beta-debug | | version_comment | Source distribution | | version_compile_machine | x86_64 | | version_compile_os | suse-linux-gnu | +-------------------------+---------------------+ Ataupun dapat dilakukan untuk query SELECT, contohnya :shell> mysql -uroot --xml -e 'SELECT * FROM xmltest.cities ORDER BY name'
<resultset statement="SELECT * FROM xmltest.cities ORDER BY name" xsi="http://www.w3.org/2001/XMLSchema-instance"><row> <field name="name">Ciudad de Méico</field> <field name="country">Mexico</field> <field name="population">8591309</field> </row>
<row><field name="name">Istanbul</field> <field name="country">Turkey</field> <field name="population">8787958</field> </row>
<row><field name="name">Jakarta</field> <field name="country">Indonesia</field> <field name="population">9604900</field> </row>
<row><field name="name">Karachi</field> <field name="country">Pakistan</field> <field name="population">9269265</field> </row>
<row><field name="name">Moscow</field> <field name="country">Russian Federation</field> <field name="population">8389200</field> </row>
<row><field name="name">Mumbai (Bombay)</field> <field name="country">India</field> <field name="population">10500000</field> </row>
<row><field name="name">New York</field> <field name="country">United States</field> <field name="population">8008278</field> </row>
<row><field name="name">São Paulo</field> <field name="country">Brazil</field> <field name="population">9968485</field> </row>
<row><field name="name">Seoul</field> <field name="country">South Korea</field> <field name="population">9981619</field> </row>
<row><field name="name">Shanghai</field> <field name="country">China</field> <field name="population">9696300</field> </row> </resultset>
Tidak ada komentar: