| Category: | Utility Scripts |
| Author/Contact Info | Adam Monsen <adamm@wazamatta.com> http://adammonsen.com |
| Description: | This will give counts for the number of tables in each database in a MySQL server as well as provide a total number of tables in all databases in a given server. |
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect('DBI:mysql:database=test', 'root');
my $databases = $dbh->selectall_arrayref('show databases');
my @all_tables;
for my $db (@$databases) {
$dbh->do("use $db->[0]");
my $tables = $dbh->selectall_arrayref('show tables');
push @all_tables, map { $_->[0] } @$tables;
print @$tables." tables in database '$db->[0]'.\n";
}
print @all_tables." Tables, total.\n";
|
|
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: count tables in all databases of a mysql server
by cLive ;-) (Prior) on Apr 11, 2004 at 08:00 UTC |