This recipe is specific to Google Compute Engine and you can use it only if you have a situation when you can stop existing MySQL for a while.

Preparations:

  • safely stop slave (in mysql: STOP SLAVE; FLUSH TABLES;) – see: http://www.jonathanlevin.co.uk/2010/05/how-to-safetly-restart-your-mysql-slave.html
  • stop mysql service (sudo service mysql stop)
  • edit /etc/mysql/my.cnf file:
    • add line into [mysqld] part:
      • skip-slave-start
      • (just precaution in case next step, preventing mysql service from starting will not successful – do not laugh – mistakes happen every day…)
    • comment out line with “server-id”
  • make changes to prevent mysql service from starting – according to OS you have – http://askubuntu.com/questions/19320/how-to-enable-or-disable-services
  • stop instance (sudo shutdown -h 0)
  • check in Google Web Console instance is really down.
  • make snapshot of disk
  • clone instance to other name + use option to create boot disk from snapshot
  • start old instance, check if mysql service is not running (ps -ef|grep mysql) – if so, stop it (sudo service mysql stop)
  • revert changes in /etc/mysql/my.cnf, revert changes preventing mysql service start
  • reboot old instance (sudo reboot)
  • check master status – SHOW MASTER STATUS;
  • check mysql on old instance – SHOW SLAVE STATUS\G
  • start new instance
  • edit /etc/mysql/my.cnf:
    • remove “skip-slave-start”
    • uncomment “server-id” but change it to some number which is not used (check on master; SHOW SLAVE HOSTS;)
  • revert changes preventing mysql service from start
  • reboot new instance and check its slave status (SHOW SLAVE STATUS\G)
  • check status on master + slave hosts (SHOW MASTER STATUS; SHOW SLAVE HOSTS)

Until current binary logs are present on master you can repeat this recipe to create as many replicas as you want. Every replica just has to have different server-id.