Comparing MySQL database versions data

Hello,

This is a script I needed recently to compare the data between two versions of a MySQL database, that was after a crash that happened to a live database and some tables got corrupted so I needed to know what has happened and in the same time there was some new data rows added to tables in the corrupted database that I can't lose,

Searching for a little bit, I found no solution to compare the database versions except some paid tool from redgate, where I won't pay and won't crack :D

anyway, I found some perl script program that can compare database tables and added a shell script file to use that tool to compare the whole database.

Being ignorant to licensing and redistributing, and not halving much time to understand that I will refer to the source tool and the script I wrote to use this tool to compare the whole database

1-mysql_coldiff

2-

#!/bin/sh
# Author: Abdalla Hassan, 6-April-2014; copyright: GPL >= 2
# Using the script is your own responsibility, If it killed your neighbour's dog, its your own problem!
while getopts u:p:h:s:d: option
do
        case "${option}"
        in
                u) USERNAME=${OPTARG};;
                p) PASSWORD=${OPTARG};;
                h) HOST=${OPTARG};;
                s) DB1=$OPTARG;;
                d) DB2=$OPTARG;;
        esac
done

if [[ -z "$USERNAME" ]] || [[ -z "$PASSWORD" ]] || [[ -z "$HOST" ]] ||[[ -z "$DB1" ]] || [[ -z "$DB2" ]]
then
echo "usage : compare.sh -u <mysql server username> -p <password> -h <host name> -s <source db> -d <destination db>"
exit
fi

tables=($(mysql -p$PASSWORD $DB1 -u$USER -h$HOST -e'show tables;'))
unset tables[0]
for table in ${tables[*]}
do
indexes=($(mysql -p$PASSWORD $DB1 -u$USER -h$HOST -e"show index from "${table}";"))
./mysql_coldiff -u$USER -p$PASSWORD -h$HOST -i "${indexes[17]}" "$DB1"."${table}" "$DB2"."${table}" > diff/"${table}" 
count_no_new=($(grep -c "There are no values of" diff/"${table}"))
count_pluses=($(grep -c "+--" diff/"${table}"))
if [ $count_no_new == 2 ] && [ $count_pluses == 0 ]
then
rm -rf diff/"${table}"
fi
echo "${table} Done"
done

Download the tool, extract it, create a folder called "diff", put this script in a new sh file then run it and the comparison results will be in the diff folder.

Cheerz.