Thesqldiff utility on all tables

MySQL

I am using the mysql diff tool at http://dev.mysql.com/doc/mysql-utilities/1.3/en/mysqldiff.html

It works great but I have to do this for each table

mysqldiff --difftype=differ --server1=PASSWORD@localhost --server2=root:PASSWORD@localhost pos.phppos_additional_item_numbers:compare.phppos_additional_item_numbers

Is there a way to have this repeat on all tables without writing a script?

If I remove the table names it just compare the name and NOT the schema of tables

Best Answer

I found a solution to my problem; here is what I did:

<?php
ini_set('display_errors', 1);
set_time_limit(0);
$db_host = 'localhost';
$db_user = 'root';
$db_password = 'PASSWORD';
$db_1 = $argv[1];
$db_2 = $argv[2];
$verbose = isset($argv[3])? '-'.$argv[3] : '';

$conn = mysqli_connect($db_host, $db_user, $db_password, $db_1);
$show_tables_query = mysqli_query($conn, 'SHOW tables');

$tables = array();
while ($row = mysqli_fetch_assoc($show_tables_query)) 
{ 
    $tables[] = $row['Tables_in_'.$db_1];
}

foreach($tables as $table)
{
    echo "$table\n*******************************\n\n";
    system("mysqldiff $verbose --difftype=differ --server1=$db_user:$db_password@$db_host --server2=$db_user:$db_password@$db_host $db_1.$table:$db_2.$table"); 
    echo "\n\n";
}

?>