Gives you binaries like mysql2csv, mysql2json, and mysql2xml, and Ruby classes to match.
Ruby
Latest commit ac14108 Feb 6, 2013 @seamusabshere missing
Permalink
Failed to load latest commit information.
benchmark use mysql2 and its :stream option (if available) Mar 15, 2012
bin stop using autoload and string keys Jan 16, 2012
lib (danger) new gem versions and syntax Apr 20, 2012
test (danger) new gem versions and syntax Apr 20, 2012
.gemtest proper handling of encoding May 9, 2011
.gitignore benchmarking Mar 14, 2011
CHANGELOG (danger) new gem versions and syntax Apr 20, 2012
Gemfile use mysql2 and its :stream option (if available) Mar 15, 2012
LICENSE
README.rdoc simplify encoding and json Jan 16, 2012
Rakefile stop using autoload and string keys Jan 16, 2012
mysql2xxxx.gemspec (danger) new gem versions and syntax Apr 20, 2012

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