Script to export MySQL tables to csv

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jandre

    #1

    Script to export MySQL tables to csv

    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

  • Steve Holden

    #2
    Re: Script to export MySQL tables to csv

    Jandre wrote:[color=blue]
    > 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.
    >[/color]
    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
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/

    Comment

    • Larry Bates

      #3
      Re: Script to export MySQL tables to csv

      Jandre wrote:[color=blue]
      > 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
      >[/color]
      I recently had a need to do exactly what you are describing and
      found this product to fit the bill nicely.



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

      Larry Bates

      Comment

      • Gerhard Häring

        #4
        Re: Script to export MySQL tables to csv

        Jandre wrote:[color=blue]
        > 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. [...][/color]

        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

        Comment

        • Jandre

          #5
          Re: Script to export MySQL tables to csv

          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

          Comment

          • Jandre

            #6
            Re: Script to export MySQL tables to csv

            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

            Comment

            Working...