0

I already read a few threads here and I also went through the MySQL Replication Documentation (incl. Cluster Replication), but I think it's not what I really want and propably too complicated, too.

I got a local and a remote DB that might get both accessed/manipulated by 2 different persons at the same time. What I'd like to do is to sync them as soon as possible (means instantly or as soon the local machine goes online). Both DB's only get manipulated from my own PHP Scripts.

My approach is the following:

If local machine is online:

  1. Let my PHP Script on the loal machine always send the SQL Query to the remote DB too
  2. Let my PHP Script on the remote machine always store its queries and...
  3. ...let the local machine ask the remote DB every x minutes for new queries and apply them locally.

If local machine is offline:

Do step 2. also for both machines and send the stored queries to the remote DB as soon as
local machine goes online again. Also pull the queries from the remote machine for sure.

My questions are:

  1. Did I just misunderstand Replication or am I right that my way would be easier in my case? Or is there any other good solution for what I'm trying to accomplish?
  2. Any idea how I could check whether my local machine is online/offline? I guess I'd have to use JavaScript, but I don't know how. The browser/my script would always be running on the local machine.

1 Answer 1

3

What you're describing is master-master or multi-master replication. There are plenty of tutorials on how to set this up across the web. Definitely do your research before putting a solution like this into production as replication in MySQL isn't exactly elegant -- you need to know how to recover if (when?) something goes wrong.

4
  • 1
    +1 - I would say don't try to re-invent this wheel. Too much time and effort has been put into MySQL replication to solve its many, many complexities. It effectively does what you describe using the binary logs to store the queries issued so slaves can be updated. See master-master replication if that is what you need, but master-slave configuration is really not that difficult, just follow their directions step by step. I think ultimately it will resolve many headaches and future problems.
    – drew010
    Sep 30, 2011 at 2:54
  • I'm too stupid to find my way through the Documentation, not my day. Now hoping I'm allowed to access the remote servers mysql configuration file. Thank you guys!
    – Anonymous
    Sep 30, 2011 at 3:18
  • Just got told that my hoster doesn't support Replication, unless I take a really expensive package - is this the standard procedure ? Otherwise I propably have to use my solution anyway :/
    – Anonymous
    Sep 30, 2011 at 3:58
  • 1
    When you say they don't "support" replication, that could mean either (1) that your database is on a server shared with other people, or (2) that they don't provide technical support for a replication setup -- I'm going to assume the former. One way around this is to use a (pair of) VPS, but it'll cost more and you'll have to set up and manage the server yourself. Alternatively, you can build logic to read/write to two databases in PHP but it's certainly non-trivial. Sep 30, 2011 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.