Created
July 4, 2011 06:52
-
-
Save DoktahWorm/1062992 to your computer and use it in GitHub Desktop.
irb db sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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