Created
November 30, 2011 06:07
-
-
Save xianhuazhou/1408232 to your computer and use it in GitHub Desktop.
show create tables from a database
This file contains hidden or 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
| #!/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