Migrate mysql with minimal downtime
- Login to existing mysql server.
- Change the configuration
/etc/my.cnf, add the following
- To make sure your configuration is correct, run
- For the mysql process to pick up these, you need to run
sudo service mysql restartand verify with
- Take a consistent snapshot of mysql. Keep a note of these values --
- Start a new server with this volume (from snapshot).
- Restart mysql
- On cli,
STOP SLAVE; CHANGE MASTER TO MASTER_HOST='<ip-address>', MASTER_USER='<username>', MASTER_PASSWORD='<password>', MASTER_LOG_FILE='<value of master_log_file>', MASTER_LOG_POS= <value of master_log_pos>; START SLAVE;
show slave statuswill show the lag between master and slave. Make sure they're in sync.
- Point your application to slave.
- Once writes are coming to slave, and master is idle
On slave cli:
stop slave; reset slave;
- Terminate your master. New slave is now a standalone mysql server.