Mysql – How to auto replicate specific columns only from a table in MySQL

data synchronizationMySQLreplication

I want to make one master DB which replicates specific user data into other databases such as:

  • username
  • pass (hashed)
  • email
  • pin (hashed)
  • timezone (int)

They are all in one table and running on MySQL 5.5.37 (possible to update to 5.6).

The reason I want to do this is because I have multiple sites using different databases and they all have different logins. Once I get this done I can enable SSO across them and save more than 50 % of the users a big hassle to not signup more that once on the different sites.

Where should I start? Is there any good info to read? I've been looking in the MySQL help files but could not find any info on how to do this for specific rows.

Best Answer

Why not create one separate db for your SSO, which is accessible for each site? Copying data around will create problems when two sites are editing "the same field".

If you only want to use a copy to set up, you could:

CREATE TABLE newdb.users LIKE otherdb.users;
INSERT newdb.users SELECT * FROM otherdb.users;

If you really want to continuously synchronise tables between databases, you will have to do it with a custom script. Most important to consider in that case, will be the question of what to do when conflicts arise? But I would really consider creating one specific db for SSO.