Skip to content

Instantly share code, notes, and snippets.

@DoktahWorm
Created July 4, 2011 06:52
Show Gist options
  • Save DoktahWorm/1062992 to your computer and use it in GitHub Desktop.
Save DoktahWorm/1062992 to your computer and use it in GitHub Desktop.
irb db sample
irb
require 'rubygems'
require 'mysql'
db_conn = Mysql.connect('hostname', 'username', 'password', 'database')
# Get an array of all the dbs and then iterate through them
dbs = db_conn.list_dbs.each do |db|
# print the name of the db
puts "db: #{ db }"
#switch the connection to use that db (same as doing "use database 'foo'" at the mysql prompt)
db_conn.select_db( db )
# print all of that db's tables
puts db_conn.list_tables
end
puts db_conn.list_dbs
puts db_conn.list_tables
# Show all the methods for the current object, sorted alphabetically.
puts db_conn.methods.sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment