Don't forget master infos in your MySQL dump

Monday, February 20, 2017 · 1 minute · 123 words

MySQL

I tried to resync a slave MySQL after it disconnected from the master. But the binary log was already deleted on master, so the only solution was to restore from the last backup. To avoid lock tables on the master and remember the binary log name and position to put them on the slave configuration, there is a tip to take care of all that : the “- master-data” option in mysqldump.

mysldump --master-data -l -q yourbase > backup.sql

This will add all information needed on the slave side : just stop the slave before restoring the dump, and restart it after.

mysql yourbase -e "stop slave"
mysql yourbase < backup.sql
mysql yourbase -e "start slave"
mysql yourbase -e "show slave status \G"
dev howto mysql