Pfft. Efficiency, schmefficiency. Here's a version in perl:

#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use MySQL::Config qw(parse_defaults);

die "$0: specify exactly 2 arguments ($0 table_1 table_2)\n" if @ARGV != 2;

my %mysql_cfg = parse_defaults "my", ['client'];

my $user = $mysql_cfg{'user'} || $ENV{'USER'};
my $pass = $mysql_cfg{'password'};

my %tables;

foreach my $db (@ARGV) {
   my $dbh = DBI->connect("DBI:mysql:database=$db", $user, $pass) || die;

   for (@{ $dbh->selectall_arrayref('SHOW TABLE STATUS') }) {
       $tables{$db}{$_->[0]} =
         $dbh->selectrow_array("SELECT COUNT(1) FROM $_->[0]");
   }
}

foreach my $table (sort keys %{ $tables{$ARGV[0]} }) {
   printf("Table `%s` differs (%d rows in %s, %d rows in %s)\n",
          $table,
          $tables{$ARGV[0]}{$table}, $ARGV[0],
          $tables{$ARGV[1]}{$table}, $ARGV[1])
     if $tables{$ARGV[0]}{$table} != $tables{$ARGV[1]}{$table};
}

Run like so:

$ ./whee.pl production standby
Table `users` differs (6 rows in production, 8 rows in standby)

____________________________________________________________
Eamon Daly



----- Original Message ----- From: "Michael J. Pawlowsky" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 14, 2004 12:19 PM
Subject: Re: Number of Rows in DB.



Thanks Eamon... I will think about it... But I'm looking at almost 1,000,000 rows.
Not sure this is the most effecient way. But I do appreciate the effort!


I think the idea of a php script that loops through "show tables" to get the table names and then does a "Select COUNT(*)" on each one and sums it up would probably be more effecient.

Cheers,
Mike


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to