mysql and XML output

So… How many of you have ever used mysql -X?

I just discovered it today, while screwing around with dumping database queries into Atom. While I’m not entirely sure it’s what I need to use, this is pretty nifty:

$ mysql -Xp -udbagg3 dbagg3 -e '
> select id, title, modified 
> from feed
> order by modified 
> limit 4' 
Enter password:

<?xml version="1.0"?>

<resultset statement="select id, title, modified 
        from feed order by modified limit 4">
  <row>
    <id>527</id>
    <title>Channel Dean</title>
    <modified>2004-03-04 15:56:54</modified>
  </row>

  <row>
    <id>31</id>
    <title>chocolate and vodka</title>
    <modified>2004-07-21 21:30:08</modified>
  </row>

  <row>
    <id>183</id>
    <title>floating atoll</title>
    <modified>2004-07-31 14:09:27</modified>
  </row>

  <row>
    <id>24</id>
    <title>What's Your Brand Mantra?</title>
    <modified>2004-08-02 03:15:03</modified>
  </row>
</resultset>

Now, while I don’t think that using this for dbagg3 is all that great an idea, it’s something I need to remember for future shell and XSLT hacks…

3 Comments

  1. iamsure
    Posted August 23, 2004 at 3:47 am | Permalink

    Is there a way to do so without the commandline option, ie, via a select call, etc?

  2. bosshoff
    Posted April 20, 2005 at 12:22 pm | Permalink

    There is a better way, using mysqldump, explained here: http://insight.zdnet.co.uk/software/developer/0,39020469,2112200,00.htm

  3. Rededog027
    Posted July 19, 2007 at 6:51 pm | Permalink

    That is awesome I haven’t used it before but it is extreamly useful for creating changelogs from svn and bugzilla :)

One Trackback

  1. By Kev's Useless Bollocks on August 23, 2004 at 2:42 am

    MySQL & XML

    Well I’ve learned something new today. Didn’t know MySQL could dump results as XML when using mysql -X on the…

Post a Comment

Your email is never shared. Required fields are marked *

*
*