Created
March 9, 2012 21:12
-
-
Save stephan-buckmaster/2008727 to your computer and use it in GitHub Desktop.
mysql: drop all databases
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
# a ruby script | |
get_database_list_command = "mysql -u root -p -e 'show databases' | grep -v Database | grep -v 'information' | grep -v 'mysql'" | |
database_names = ` #{get_database_list_command} `.split(/\n/) | |
drop_databases_sql_statements = database_names.collect { |db| "drop database if exists `#{db}`;" if db.length > 0}.compact.join(' ') | |
puts 'Executing drop commands:' | |
puts drop_databases_sql_statements | |
puts drop_databases_sql_statements.split(/;/).join(";\n") | |
drop_databases_shell_command = "mysql -u root -p -e '#{drop_databases_sql_statements}'" | |
puts ` #{drop_databases_shell_command } ` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment