title: How does MySQL replication work?
body: <p>I have a questions here about MySQL replication. I have a very limited knowledge about database. Please someone help me to clarify this. My goal is to be able to do a deployment that can avoid downtime.</p>
  
  <p>Suppose I have a DB replicated (master and slave). Suppose I want to do a new release, and I need to run a migration script. My plan is to stop the replication. And run the script in the slave. The migration script can be as:</p>
  
  <ul>
  <li>Based on some business logic, running multiple queries to set new values for a column in a table.</li>
  <li>Adding new column</li>
  </ul>
  
  <p>What would actually happen when I start the replication again? The slave will catch up of any changes on the master. But how would the master get the changes that was applied to the slave? If i run the same database script, the migration script won't be run again against the same data set on the master.</p>
  
  <p>Would it make sense, if once the slave catch up with the master, to use the snapshot of the slave and use it as the new slave. And old slave become master?</p>
  
  <p>I hope this actually is clear.  Thanks. Any help is really appreciated.</p>