Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MySQL backup for replication

Put database in read-only mode and capture master log position:

mysqL> FLUSH TABLES WITH READ LOCK; SET GLOBAL read_only = ON; SHOW MASTER STATUS;`

Copy entire mysql data folder:

bash> cp -r /var/lib/mysql /home/me/prod_varlibmysql20170715 ; date`

When copy is complete, immediately turn off read-only mode:

mysqL> SET GLOBAL read_only = OFF; UNLOCK TABLES;`

Rename backup file to include master position, this makes it easier and safer to setup the slave:

bash> mv /home/me/prod_varlibmysql20170715 /home/me/prod_mysql-bin.000014_64936180_varlibmysql20170715
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment