Script to export MySQL tables to csv

J

Jandre

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 can get all the data using
MySQL front, but this has to be done tabe-by-table, and is too time
consuming.

I am new to Python and also new to programming.
Can anyone please help.

Thanks
Jandre
 
S

Steve Holden

Jandre said:
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 can get all the data using
MySQL front, but this has to be done tabe-by-table, and is too time
consuming.

I am new to Python and also new to programming.
Can anyone please help.
Well, it might be a rather extending first programming project, but the
delightful news is that you can access MySQL databases directly from Python!

What sort of differences will exist? Does a row's content always stay
the same once it's been written to a table, or are rows updated as well?

Basically if you can say what type of differences you want to see it
should be possible to do just what you want.

If you haven't already downloaded and installed the MySQLdb module for
Python you'll probably need that. Are you running on Windows or a
Unix-like system (you'll need to get the appropriate installer from

http://sourceforge.net/projects/mysql-python

If you have any trouble installing it, get back on this list and someone
will help.

You're going to have *such* fun!

regards
Steve
 
L

Larry Bates

Jandre said:
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 can get all the data using
MySQL front, but this has to be done tabe-by-table, and is too time
consuming.

I am new to Python and also new to programming.
Can anyone please help.

Thanks
Jandre
I recently had a need to do exactly what you are describing and
found this product to fit the bill nicely.

http://www.apexsql.com/sql_tools_diff.asp

Sometimes I find it better to buy than to write ;-).

Larry Bates
 
?

=?ISO-8859-1?Q?Gerhard_H=E4ring?=

Jandre said:
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
 
J

Jandre

Thnaks to everybody for their input. I have found a quick fix for now.
MySQL dump allows me to export the data to XML which can easily be
compared. This will help me for now and the project will have to wait
until I have some more time.

Regards
Jandre
 
D

Dennis Lee Bieber

Thnaks to everybody for their input. I have found a quick fix for now.
MySQL dump allows me to export the data to XML which can easily be
compared. This will help me for now and the project will have to wait
until I have some more time.
mysqldump should also allow for CSV... Check the options:

--fields-terminated-by
--fields-enclosed-by
--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
474,270
Messages
2,571,352
Members
48,034
Latest member
BettinaArn

Latest Threads

Top