{"id":2234,"date":"2013-07-12T15:07:45","date_gmt":"2013-07-12T07:07:45","guid":{"rendered":"http:\/\/rmohan.com\/?p=2234"},"modified":"2013-07-12T15:07:45","modified_gmt":"2013-07-12T07:07:45","slug":"mysql-master-slave-replication-after-slave-fails","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2234","title":{"rendered":"Mysql Master-Slave Replication after slave fails"},"content":{"rendered":"<p>1. From slave if we run\u00a0<b>mysql&gt; mysql slave status<\/b>;<br \/>\nit will show last bin file slave reads from master<br \/>\nand all,so\u00a0start from that bin file to sink with master to slave.<\/p>\n<p>2. Set Master configuration on the Slave.<br \/>\nExecute the following command on a MySQL prompt to sink slave with master:<\/p>\n<p><b>mysql &gt; CHANGE MASTER TO MASTER_HOST=\u201910.100.10.80\u2019, MASTER_USER=\u2019repl\u2019, MASTER_PASSWORD=\u2019slavepassword\u2019, MASTER_LOG_FILE=\u2019mysql-bin.000003\u2019, MASTER_LOG_POS=106;<\/b><\/p>\n<p>This is how you tell Slave how to connect to Master in order to replicate. Note the log coordinates. These are the coordinates you got from step 1 above.<\/p>\n<p>[<br \/>\nNow we need to tell the slave where the master is located, which binlog file to use, and which position to start. Issue this\u00a0<b>CHANGE MASTER TO\u00a0<\/b><br \/>\ncommand on the slave server(s): (don\u2019t forget to change the values to match your master server)<\/p>\n<p><b>\u00a0mysql&gt; CHANGE MASTER TO<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_HOST=&#8217;master IP address&#8217;,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_USER=&#8217;replication user&#8217;,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_PASSWORD=&#8217;replication user password&#8217;,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_PORT=3306,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_LOG_FILE=&#8217;mysql-bin.000015&#8242;,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_LOG_POS=540,<\/b><br \/>\n<b>\u00a0 \u00a0 -&gt; \u00a0 MASTER_CONNECT_RETRY=10;<\/b><\/p>\n<p><b>mysql&gt; show warnings\\G<\/b><\/p>\n<p>Two values to note in the slave status shows us that our CHANGE MASTER TO statement worked:<br \/>\n<b><br \/>\n<\/b><b>\u00a0 \u00a0 Master_Log_File: mysql-bin.000015<\/b><br \/>\n<b>\u00a0 \u00a0 Read_Master_Log_Pos: 540<\/b><br \/>\n]<\/p>\n<p>3.\u00a0<b>Stop MySQL<\/b><\/p>\n<p>4.\u00a0<b>Start MySQL normally<\/b><\/p>\n<p>Checking out that everything is OK<\/p>\n<p>Having started the slave MySQL node, you can log in and issue some commands to make sure that Slave is running OK.<\/p>\n<p>On mysql prompt, give the following command:<\/p>\n<p><b>mysql&gt; show processlist;<\/b><br \/>\n<b><br \/>\n<\/b>You can see the SQL thread that gets data from Master (in the above output is the thread with Id 2) and the SQL thread that executes the statements on Slave\u00a0(in the output is the thread with Id 1).<\/p>\n<p>2.\u00a0<b>mysql&gt; show slave status;<\/b><\/p>\n<p>This will display the current status on slave. Pay attention to the\u00a0<b>*_Errno<\/b>\u00a0and\u00a0<b>*_Error columns<\/b>.\u00a0Normally, you shouldn\u2019t see anything that indicates existence of errors there.<\/p>\n<p>3. On mysql prompt, give the following command<br \/>\n<b><br \/>\n<\/b><b>mysql&gt; show status like \u2018Slave%\u2019;<\/b><br \/>\n<b><br \/>\n<\/b>You should see an output like the following:<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+<br \/>\n| Variable_name \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| Value |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+<br \/>\n| Slave_open_temp_tables \u00a0 \u00a0 | 0 \u00a0 \u00a0 |<br \/>\n| Slave_retried_transactions | 0 \u00a0 \u00a0 |<br \/>\n| Slave_running \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0| ON \u00a0 \u00a0|<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+<\/p>\n<p>Pay attention to Slave_running being with value\u00a0<b>ON<\/b>.<\/p>\n<p>Important note on binary log time to live<\/p>\n<p>As we have said before, you can have Slave down and<br \/>\nre-synchronize as soon as you bring it up again.But do not put it out of service for quite long because, then it will be impossible to synchronize its content with Master.<\/p>\n<p>This is because the binary logs on Master do not leave forever.<\/p>\n<p>There is the variable with name\u00a0<b>expire_logs_days<\/b>\u00a0that determines the number of days for automatic binary log file removal. Check this out.\u00a0This should be 10, meaning that if you ever have your Slave down for 10 days or more, it will not be able to do replication as soon as you bring it up,\u00a0and you will have to \u00a0everything from the beginning.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. From slave if we run mysql&gt; mysql slave status; it will show last bin file slave reads from master and all,so start from that bin file to sink with master to slave.<\/p>\n<p>2. Set Master configuration on the Slave. Execute the following command on a MySQL prompt to sink slave with master:<\/p>\n<p>mysql &gt; [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2234"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2234"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2234\/revisions"}],"predecessor-version":[{"id":2235,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2234\/revisions\/2235"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}