Skip to content

Instantly share code, notes, and snippets.

@Navinnair
Created June 7, 2016 12:09
Show Gist options
  • Save Navinnair/50b68f7664de579f0b4c74452661ab23 to your computer and use it in GitHub Desktop.
Save Navinnair/50b68f7664de579f0b4c74452661ab23 to your computer and use it in GitHub Desktop.
require 'yaml'
dbconfig = YAML::load(File.open('config/database.yml'))
tables_to_export = %w[ users students ]
destination_folder = 'tmp'
db_conf = 'config/database.yml'
db = YAML::load(File.open( db_conf ))["production"]
tables_to_export.each do |table|
dest_file = File.join( destination_folder, "#{table}.csv" )
command_dump = "mysql -B -u#{db["username"]} -p#{db["password"]} #{db["database"]} -e 'SELECT * FROM #{table};' > #{dest_file}"
puts "CSV exporting #{table} to #{dest_file}"
system( command_dump )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment