Skip to content

Instantly share code, notes, and snippets.

@xianhuazhou
Created November 30, 2011 06:07
Show Gist options
  • Select an option

  • Save xianhuazhou/1408232 to your computer and use it in GitHub Desktop.

Select an option

Save xianhuazhou/1408232 to your computer and use it in GitHub Desktop.
show create tables from a database
#!/usr/bin/env ruby
# encoding: UTF-8
# show create tables from a database
require 'mysql2'
m = Mysql2::Client.new :username => 'root', :password => '', :host => 'localhost', :database => 'dbname'
result = m.query("SHOW TABLES").collect do |row|
table = row['Tables_in_dbname']
puts table
puts m.query("SHOW CREATE TABLE #{table}").first['Create Table']
puts
end
m.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment