Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

count tables in all databases of a mysql server

by meonkeys (Chaplain)
on Apr 11, 2004 at 06:44 UTC ( [id://344217]=sourcecode: print w/replies, xml ) Need Help??
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
    timtowtdi - if you have root access to the machine, you could always do this in the shell instead:
    cd /usr/local/mysql/var; find . -name *.MYD |wc -l
    cLive ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://344217]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-03-29 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found