Compare similar tables from separate MySQL servers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keleathi
    New Member
    • Jun 2007
    • 1

    Compare similar tables from separate MySQL servers

    I'm pulling in data from two servers over two SSH tunnels. The tables on each of the servers have the same fields, 8 in total. I need a way to see if an entry that is in the first server is also on the second server. Out of 8 of the fields, 5 will have to match to be considered a match (but I need to pull all 8 in order to use them in the display). I know I could use temp tables in mysql on the server running the php script, but I'd much rather do this all in php.

    All said, I haven't found a way to compare such large amounts of data matching on multiple fields all within php. Any help would be greatly appreciated!
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, keleathi. Welcome to TSDN!

    The tricky part (I'm assuming) is that you can't just go line-by-line because the rows might not match up. About the only thing you can do here is pick one server, load the entire table, then go through line-by-line and searching for the five required fields on the other server (remember to LIMIT 1 so that you don't keep looking after you find it!).

    Even with a lot of rows, if your tables are properly indexed, it shouldn't take too long.

    Erm... I presume that this is a one-time thing, right?

    [EDIT: I suppose you could load both tables into PHP and search each row as an array, but why reinvent MySQL?]

    Comment

    Working...