I need to track how much space is being used by each of our database (records and indexes) for disk quota reasons. Googling for it will give you many code examples in PHP. Here is a Perl equiv. It isn't super fast. Let me know if there is a better way.
$DB = DB->connect(...);
my $size = sizeOfDB($DB);
sub sizeOfDB {
my $db = shift;
my $size = 0;
my $st = $db->prepare('show table status');
$st->execute;
while (my $h = $st->fetchrow_hashref) {
# other fields in %$h could be used, for example,
# to limit the count to just certain tables.
$size += $h->{Data_length} + $h->{Index_length};
}
$st->finish;
return $size;
}