Created
September 25, 2015 16:54
-
-
Save rushipkar90/a0bd8874a42961bd68dc to your computer and use it in GitHub Desktop.
mysqldbsize.pl
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/perl | |
use File::Basename; | |
@dbs = </var/lib/mysql/*_*>; | |
%databases = (); | |
foreach $dbPath (@dbs) { | |
$db = basename($dbPath); | |
chomp($size = `du -s $dbPath`); | |
$databases{$db} = $size; | |
} | |
@sorted = sort { $databases{$b} <=> $databases{$a} } (keys(%databases)); | |
$format = "%-30s %-5s M\n"; | |
print "\nTOP 20 BIGGEST MYSQL DATABASES\n\n"; | |
foreach $key (@sorted[0..19]) { | |
$size = int $databases{$key} / 1024; | |
printf $format, $key, $size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment