an introduction is needed before diving into the procedures…
- First you need to stop Apache service on web server, or any other measure to prevent other environments from writing to your DBs:
:~$ sudo service apache2 stop - flush / reset queries & flush tables with read lock and disable keys on MASTER:
mysql> FLUSH PRIVILEGES;
mysql> FLUSH QUERY CACHE;
mysql> RESET QUERY CACHE;
mysql> DISABLE KEYS;
mysql> FLUSH TABLES WITH READ LOCK;
- take a copy of the ALL the DB’s from MASTER server:
TIP: if possible, you may want to use an IDE to export / dump since it’s easier and more user friendly - make a note of the logs on MASTER, ie mysql-bin.XXXXXX and MASTER_LOG_POS by checking the status of your master:
mysql> SHOW MASTER STATUS \G; - stop and reset slave on your SLAVE(s) server:
mysql> STOP SLAVE;
mysql> RESET SLAVE;
- on SLAVE drop DBs and import the new DBs from MASTER:
TIP: if possible, use an IDE to import ALL DB’s as it is more user friendly - reset the SLAVE and update it with master details (see step #4):
mysql> CHANGE MASTER TO MASTER_HOST=’192.168.174.1‘, MASTER_USER=’your_replication_user‘, MASTER_PASSWORD=’your_replication_password‘, MASTER_LOG_FILE=’mysql-bin.<MASTER_LOG_FILE>‘, MASTER_LOG_POS=<MASTER_LOG_POS>;
- start SLAVE and verify replication is working:
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS \G;
- unlock tables and enable keys on MASTER (apgmysql02 / apgmysql05)
mysql> UNLOCK TABLES;
mysql> ENABLE KEYS;
- on MASTER test if replication still works:
mysql> SHOW MASTER STATUS \G; - on SLAVE test if replication still works:
mysql> SHOW SLAVE STATUS \G; - start Apache service on web server (or restore any services you’ve stopped on step #1):
:~$sudo service apache2 start
- trigger some DB reads / writes in production and check replication still works (e.g. the front end of an application, or by running some maintenance tasks on master)
- communicate results to stake holders – job well done!