{"id":2941,"date":"2018-12-06T16:51:41","date_gmt":"2018-12-06T16:51:41","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=2941"},"modified":"2018-12-06T16:54:50","modified_gmt":"2018-12-06T16:54:50","slug":"resync","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=2941","title":{"rendered":"Resync mysql master and slave without master downtime"},"content":{"rendered":"<p>On the Master server dump a backup of the database you want to resync<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">mysqldump --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 -q &lt;&lt;dbname&gt;&gt; &nbsp;| gzip -c &gt; ~\/dump.sql.gz<\/div><\/div>\n<p>Move compress backup to Slave server<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">scp ~\/dump.sql.gz &lt;&lt;user&gt;&gt;@&lt;&lt;slave-server-ip&gt;&gt;:~\/<\/div><\/div>\n<p>On the Slave server decompress the backup<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">gunzip ~\/dump.sql.gz<\/div><\/div>\n<p>Get the Master Log Name and Position from the dump, Make a note of the MASTER_LOG_FILE &#038; MASTER_LOG_POS values<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">head dump.sql -n80 | grep &quot;MASTER_LOG_POS&quot;<\/div><\/div>\n<p>Stop mySQL\/MariaDB<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">service mysql stop<\/div><\/div>\n<p>Put the following option in your my.conf config file (most probably under \/etc\/my.conf) under the [mysqld] section to disable the slave from auto starting<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">skip-slave-start<\/div><\/div>\n<p>Start mySQL\/MariaDB<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">service mysql start<\/div><\/div>\n<p>Log into mySQL and check the Slave is off<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">mysql -u root -p<br \/>\nSHOW SLAVE STATUS \\G;<br \/>\nexit;<\/div><\/div>\n<p>Load backup into Slave server<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">mysql -u root -p &lt;&lt;dbname&gt;&gt; &lt; ~\/dump.sql<\/div><\/div>\n<p>Log into mySQL and set Master Settings<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">CHANGE MASTER TO MASTER_HOST='&lt;&lt;master-server-ip&gt;&gt;',MASTER_USER='&lt;&lt;replicant_user&gt;&gt;',MASTER_PASSWORD='&lt;&lt;password&gt;&gt;', MASTER_LOG_FILE='&lt;&lt;value from step 4&gt;&gt;', MASTER_LOG_POS=&lt;&lt;value from step 4&gt;&gt;;<\/div><\/div>\n<p>Stop mySQL\/MariaDB<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">service mysql stop<\/div><\/div>\n<p>Remove the following option in your my.conf config file (most probably under \/etc\/my.conf) under the [mysqld] section to enable the slave for auto starting<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">skip-slave-start<\/div><\/div>\n<p>Start mySQL\/MariaDB<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">service mysql start<\/div><\/div>\n<p>Log into mySQL and check the Slave is On.  Take Note of the Seconds_Behind_Master . This will decrease as the Slave server catches up with the Master server.<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">mysql -u root -p<br \/>\nSHOW SLAVE STATUS \\G;<br \/>\nexit;<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>On the Master server dump a backup of the database you want to resync mysqldump &#8211;skip-lock-tables &#8211;single-transaction &#8211;flush-logs &#8211;hex-blob &#8211;master-data=2 -q &lt;&lt;dbname&gt;&gt; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2941","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2941"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/2941\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}