I have 2 MySQL dump files. I want to find the table data difference between 2 tables.
I have 2 MySQL dump files. I want to find the table data difference between 2 tables.
This was very useful for me, so adding my two cents:
git diff --word-diff=color dump1.sql dump2.sql | less -R
I just had to add lines breaks at ),('s so that each record becomes a separate line. Then the result can be fed to a tool like diff. This command does the job:
FORMAT_="s/),(/),\n(/g"
diff <(sed $FORMAT_ old-dump.sql) <(sed $FORMAT_ new-dump.sql)
Here's what I use. It works.
#!/bin/bash
# Do a mysqldump of the a db, once a day or so and diff to the previous day. I want to catch when data has changed
# Use the --extended-insert=false so that each row of data is on a single line, that way the diff catches individual record changes
mv /tmp/dbdump0.sql /tmp/dbdump1.sql 2>/dev/null
mysqldump -h dbhostname.com -P 3306 -u username -p password --complete-insert --extended-insert=false dbname > /tmp/dbdump0.sql
# Ignore everything except data lines
grep "^INSERT" /tmp/dbdump0.sql > /tmp/dbdump0inserts
grep "^INSERT" /tmp/dbdump1.sql > /tmp/dbdump1inserts
diff /tmp/dbdump1.sql /tmp/dbdump0.sql > /tmp/dbdumpdiffs
r=$?
if [[ 0 != "$r" ]] ; then
# notifier code remove
fi