Script to export MySQL tables to csv

Gerhard Häring gh at ghaering.de
Thu Nov 10 18:32:19 CET 2005


Jandre wrote:
> To anyone that can help
> 
> I have 2 MySQL databases that contain large amounts of tables. I need
> to be able to compare the data in the tables with older/newer versions
> of the tables. I figured the easiest way would be to get the info in
> csv format and then run a comparison. [...]

I think the easiest way to compare tables in a SQL-based database is 
using SQL ...

What about exporting the tables from the databases, importing those you 
want to compare into one database and then using set-operations in SQL 
using MINUS, INTERSECT. For example:

select c1, c2, c3 from table1
intersect
select c1, c2, c3 from table2;
-- return data common in both tables

select c1, c2, c3 from table1
minus
select c1, c2, c3 from table2;
-- data only in table1

etc.

You can export specific tables from a MySQL database using the mysqldump 
commandline tool and then load them into the other database.

HTH,

-- Gerhard




More information about the Python-list mailing list