Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Gives you binaries like mysql2csv, mysql2json, and mysql2xml, and Ruby classes to match.
Ruby
Branch: master

README.rdoc

mysql2xxxx

Binaries

mysql2csv --user=dbuser --password=dbpassword --database=dbname --execute="select * from automobile_makes"
mysql2json --user=dbuser --password=dbpassword --database=dbname --execute="select * from automobile_makes"
mysql2xml --user=dbuser --password=dbpassword --database=dbname --execute="select * from automobile_makes"

To see all options

mysql2csv --help

Ruby

a = Mysql2xxxx::JSON.new :user => 'dbuser', :password => 'dbpassword', :database => 'dbname', :execute => "select * from automobile_makes"
a.to_stdout                                     # write it directly to $stdout
puts a.to_s                                     # get a string
a.to_path('/tmp/outfile.json')                  # write it to a file at this path
a.to_file(File.open('/tmp/outfile.json', 'w'))  # write it to a file handle

Note also that if you're running it inside a Rails application, it will default to the ActiveRecord connection config.

a = Mysql2xxxx::JSON.new :execute => "select * from automobile_makes"  # no need to specify user, etc. because it's taken from ActiveRecord

Well-formedness

  • CSV output depends on FasterCSV to_csv

  • JSON output depends on Florian Frank's JSON JSON.generate

  • XML output is written manually, but looks like the output of mysql [hyphen][hyphen]xml

Copyright 2011 Seamus Abshere

Something went wrong with that request. Please try again.