title: Two-way mySQL database sync between hosted and local production server
body: <p>So the scenario is this:</p>
  
  <p>I have a mySQL database on a local server running on Windows 2008 Server.  The server is only meant to be accessible to users on our network and contains our companies production schedule information. I have what is essentially the same database running on a hosted server running linux, which is meant to be accessible online so our customers can connect to it and update their orders.</p>
  
  <p>What I want to do is a two-way sync of two tables in the database so that the orders are current in both databases, and a one-way sync from our server to the hosted one with the data in the other tables.  The front end to the database is written in PHP.  I will say what I am working with so far, and I would appreciate if people could let me know if I am on the right track or barking up the wrong tree, and hopefully point me in the right direction.</p>
  
  <p>My first idea is to make (at the end of the PHP scripts that generate changes to the orders tables) an export of the changes that have been made, perhaps using INSERT into OUTFILE WHERE account = account or something similar.  This would keep the size of the file small rather than exporting the entire orders table.  What I am hung up on is how to (A) export this as an SQL file rather than a CSV (B) how to include the information about what has been deleted as well as what has been inserted (C) how to fetch this file on the other server and execute the SQL statement.</p>
  
  <p>I am looking into SSH and PowerShell currently but can't seem to formulate a solid vision of exactly how this will work.  I am looking into cron jobs and Windows scheduled tasks as well.  However, it would be best if somehow the updates simply occurred whenever there was a change rather than on a schedule to keep them synced in real time, but I can't quite figure that one out.  I'd want to be running the scheduled task/cronjob at least once every few minutes, though I guess all it would need to be doing is checking if there were any dump files that needed to be put onto the opposing server, not necessarily syncing anything if nothing had changed.</p>
  
  <p>Has anyone ever done something like this?  We are talking about changing/adding/removing from 1(min) to 160 lines(max) in the tables at a time.  I'd love to hear people's thoughts about this whole thing as I continue researching my options.  Thanks.</p>
  
  <p>Also, just to clarify, I'm not sure if one of these is really a master or a slave.  There isn't one that's always the accurate data, it's more the most recent data that needs to be in both.</p>
  
  <p>+1 More Note
  Another thing I am thinking about now is to add at the end of the order updating script on one side another config/connect script pointing to the other servers database, and then rerun the exact same queries, since they have identical structures.  Now that just sounds to easy....  Thoughts?</p>