Mysql master-slave config in the.cnf

master-slave-replicationMySQL

I'm following this guide to setting up a master-slave config (https://support.rackspace.com/how-to/set-up-mysql-master-slave-replication/) and i'm confused about the end of the document where they are setting up the SLAVE

WHen setting up the slave, they suggest putting the following into the SLAVE my.cnf file

bind-address = 0.0.0.0
server-id = 2
master-host =  [private-IP-of-db01]
master-user = [replication-username]
master-password = [replication-password]
master-connect-retry = 60

Then later on they suggest logging into mysql and then telling the slave where to start replicating from

# mysql -u root -p
mysql> SLAVE STOP;
mysql> CHANGE MASTER TO MASTER_HOST='[private-IP-of-db01]',
MASTER_USER='[replication-username]',
MASTER_PASSWORD='[replication-password]',
MASTER_LOG_FILE='[file-listed-on-master-status]',
MASTER_LOG_POS=[log-position-listed-on-master-status];
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS\G

My question is specifically with the MASTER LOG FILE and MASTER LOG POS. Are these things not to be set in my.cnf on the slave?

I ask this because if I have to restart the slave mysql for whatever reason one day, how will the slave know where to pick up from? Do I have to go through the process of re-impoorting the DB to know the position again? Or do I have to save the position # before taking the slave DB down?

Thanks!

Best Answer

Are these things not to be set in my.cnf on the slave?

No, You only can set those values during execution time (using a mysql client tool)

if I have to restart the slave mysql for whatever reason one day, how will the slave know where to pick up from? Do I have to go through the process of re-importing the DB to know the position again?

MySQL stores replication variables in files located by default in the data directory (Usually theses file names contain "relay" and "master" words) and it updates those file with every transaction, so no worries, if you need to restart your slave, the server already knows how to catch up the master.