Need help to combine mysql databases

by 5 comments
Hi Warriors,

This one is beyond me, how about you?

I use a script which stores info in a mysql db. I have used the script several times on different servers.

I now want to combine one of the tables from several servers into one table.

Any ideas or help would be appreciated.



PS. The tables that I want to combine are identical, except for the information stored on them
#internet marketing #combine #databases #mysql
  • Profile picture of the author Sean Donahoe
    If the tables have the exact same structure that should not be a problem. It will depend if you have referenced index keys or primary keys which link tables with other data.

    Often times, I find it best to write a PHP script that opens all the items from the tables and place the items into an array. I then loop through the array and create a destination table to place all the data.

    I use the code to create a validation process for inserts or updates (for duplication checking etc) and any other checks needed.

    That way I can control the data process and combining of fields.

    Hope that helps.
  • Profile picture of the author Sean Donahoe
    That would work only if there was no Primary keys or crosslinked references from other tables which is why I suggest creating a simple PHP filter to run against these tables. Your PHP script then becomes a funnel for all that data into the spout (destination table).

    If you need some pseudo code:
    // Loop through each table 
        // Load in table x into Array
        // Start Loop of Array
            // Does record exist in destination?
            // Any other validation checks
            // Data integrity checks (such as crosslinked indexes)
            // Based on checks, insert, update or ignore
        // End Array Loop
    // End Table Loop
    // Report Summary
    • Profile picture of the author Rob Richards
      Thanks Jeff and Chikira, I appreciate your responses.

      You've given me just enough to make me think I know what I'm doing and just enough to get myself into a lot of trouble. :-)

      I guess I'm still floundering with this whole idea.

      Any additional suggestions?



Next Topics on Trending Feed