Getting XML and HTML output.

By | January 31, 2013

Many people use MySQL in the console to execute a simple command, but did you know that MySQL can format the result of the query directly to XML or html?

The option -X will output the query result as XML
-H can be used to generate a HTML table containing the data.

$ mysql -X -e "select * from test" test
<?xml version="1.0"?>
 
<resultset statement="select * from test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <row>
	<field name="test">152710</field>
  </row>
</resultset>

Output as HTML

$ mysql -H -e "select * from test" test
<table border="1">
<tbody>
<tr>
<th>test</th>
</tr>
<tr>
<td>152710</td>
</tr>
</tbody>
</table>

Leave a Reply