Skip to content

Instantly share code, notes, and snippets.

@memuller
Created December 29, 2010 17:08
Show Gist options
  • Save memuller/758757 to your computer and use it in GitHub Desktop.
Save memuller/758757 to your computer and use it in GitHub Desktop.
Rascunho de script p/ backup de bancos mysql
require 'mysql'
begin
db = Mysql.real_connect 'localhost', 'root' , 'alpha13'
databases_hash = {}
db.query("show databases ;").each do |database|
databases_hash.merge!( { database[0] => [] } )
end
databases_hash.each do |k, v|
db.select_db k
tables_list = []
db.query("show tables ; " ).each do |table|
tables_list << table[0]
end
databases_hash[k] = tables_list
end
databases_hash.each do |database , tables_list|
tables_list.each do |table|
puts "#{database} #{table}"
end
end
rescue Mysql::Error
echo "deu erro"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment