improve optimize script
This commit is contained in:
parent
d459760890
commit
7bde4efe1e
1 changed files with 9 additions and 7 deletions
|
@ -3,10 +3,12 @@
|
||||||
# set home as we runit as weekly cron, where HOME is /
|
# set home as we runit as weekly cron, where HOME is /
|
||||||
ENV['HOME'] = '/root'
|
ENV['HOME'] = '/root'
|
||||||
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 = %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|
|
tables.each do |table|
|
||||||
tableitems = table.chomp.split(/\t/)
|
tableitems = table.chomp.split(/\t/)
|
||||||
system "mysql #{tableitems[0]} -Bse \"OPTIMIZE TABLE \\`#{tableitems[0]}\\`.\\`#{tableitems[1]}\\`\" | grep -q OK"
|
output = %x{mysql #{tableitems[0]} -Bse "OPTIMIZE TABLE \\`#{tableitems[0]}\\`.\\`#{tableitems[1]}\\`" 2>&1}
|
||||||
if $?.to_i > 0 then
|
unless output =~ /status\t+OK/
|
||||||
puts "error while optimizing #{tableitems[0]}.#{tableitems[1]}"
|
puts "Error while optimizing #{tableitems[0]}.#{tableitems[1]}:"
|
||||||
|
puts output
|
||||||
|
puts
|
||||||
end
|
end
|
||||||
}
|
end
|
||||||
|
|
Loading…
Reference in a new issue