Created
April 11, 2012 07:26
-
-
Save joshdvir/2357573 to your computer and use it in GitHub Desktop.
Ruby optimize all tables in all DB's in mysql
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
require 'mysql' | |
con = Mysql.new('localhost','root', '') | |
rs = con.query('show databases') | |
databases = [] | |
rs.each_hash do |h| | |
databases << h['Database'] | |
end | |
databases.each do |db| | |
unless db == 'mysql' or db == 'performance_schema' or db == 'information_schema' | |
puts "on database: " + db.to_s | |
con = Mysql.new('localhost','root', '', db) | |
rs = con.query('show tables') | |
rs.each_hash do |t| | |
puts "on table: " + t['Tables_in_' + db.to_s] | |
rs = con.query('optimize table ' + t['Tables_in_' + db.to_s].to_s) | |
end | |
con.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment