How do I merge 2 *seperate* mysql databases, without duplication?

Both databases have the table “xf_user”, and the columns “email” and “username”. They both have other columns, but not all match. I just want to merge those two particular columns, overwriting/skipping duplicates, to make one unified DB.

I’m not quite sure how to proceed. Any assistance would be most appreciated!

MySQL ? PDO ?
Either way, in general, you loop thru all one you wish to copy/update using a WHILE loop.
In that loop, you have to check the second database for the same data. Assuming the xf_user is unique, you would run a second query to see if that user exists. If it exist, then you update the data. If it does not exist, you insert the data. Not too complex.
One further comment, if you have an last_updated_field in the DB that gets updated when the user changes their personal data, you would not want to update it if the first data is older than the second one.

Hope these comments make sense to you. Backup both of your databases, create the code, show us the code without any passwords or DB access info and then you can test it. Good luck !
( PS: I suggest PDO as it is less hack-able! )

1 Like

Got it! I chatted with Bing’s A.I, and it suggested I use phpmyadmin and import one DB into the other. Worked perfectly!

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service