jacobcan118
jacobcan118

Reputation: 9065

How to compare two MySQL sql file in linux without using mysql command

I have two sql file, new.sql and old.sql. New.sql may have new tables as old.sql but basically two sql data are different. What is the best way for me to compare two of them in linux if there are any new table on new.sql. Add those tables and the data from those tables into old.sql I tried to use diff old.sql new.sql > diff.txt and grep the difference and it turn out I can not volid the data difference. Like following how can i just create tablek with data k1, k2 into old.sql from new.sql

old.sql

==========
tableA
==========
col1    col2
a1      a2

==========
tableB
==========
col1    col2
b1      b2

==========
tableC
==========
col1    col2
c1      c2

new.sql

==========
tableA
==========
col1    col2
a11      a22

==========
tableB
==========
col1    col2
x1      x2

==========
tableK
==========
col1    col2
k1      k2

Upvotes: 0

Views: 820

Answers (1)

Barmar
Barmar

Reputation: 781706

Use sed to extract just the table names from the files. Use process substitution to provide these as arguments to the comm command, which will show the lines from new.sql that aren't in old.sql.

comm -13 <(sed -n '/=======/,/=======/p old.sql | sort -u) <(sed -n '/=======/,/=======/p new.sql | sort -u)

Upvotes: 2

Related Questions