module-mysql/files/optimize/optimize_tables.rb

11 lines
488 B
Ruby
Raw Normal View History

2009-02-21 18:22:47 +01:00
#!/usr/bin/env ruby
tables = %x{mysql -Bse "SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND ENGINE IN ('MyISAM','InnoDB','ARCHIVE')"}
tables.each { |table|
tableitems = table.chomp.split(/\t/)
system "mysql #{tableitems[0]} -Bse \"OPTIMIZE TABLE #{tableitems[1]}\" | grep -q OK"
2009-02-22 14:02:08 +01:00
if $?.to_i > 0 then
2009-02-21 18:22:47 +01:00
puts "error while optimizing #{tableitems[0]}. #{tableitems[1]}"
end
}