MYSQL: Possible to mirror/sync two tables in separate dbs (same server) in realtime?

StackOverflow https://stackoverflow.com/questions/12397755

  •  01-07-2021
  •  | 
  •  

سؤال

I have two databases with the exact same structure (basicly two vbulletin forums), however the data contained within the databases is different, and will be different on a minute-minute basis. I wanted to synchronize/mirror the data in one of the tables between the two databases (the tables have an identical structure and reside on the same physical server). By synchronize it would take the latest changed data and apply it to the other database table, regardless of which one was changed

Is this possible?

Thank you!!

هل كانت مفيدة؟

المحلول

If you have auto incrementing primary keys, you're hosed, so I hope you have GUIDs...

If sounds like a trigger would work for you, but each database would have to know if it was the origin of the row so as to run the insert on the other database.

Set a session variable that contains the current database name before you change the data. The trigger can compare that value to the value of DATABASE(); if the same, write the record to the other database as well.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top