{"id":7284,"date":"2018-03-22T00:33:22","date_gmt":"2018-03-21T16:33:22","guid":{"rendered":"http:\/\/rmohan.com\/?p=7284"},"modified":"2018-03-22T00:33:58","modified_gmt":"2018-03-21T16:33:58","slug":"mariadb-master-slave","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=7284","title":{"rendered":"MARIADB MASTER SLAVE"},"content":{"rendered":"<p><strong>MARIADB MASTER SLAVE<\/strong><\/p>\n<p>Install on both master and slave<\/p>\n<p>yum install mariadb-server mariadb -y<\/p>\n<p>systemctl enable mariadb<\/p>\n<p>systemctl start mariadb.service<\/p>\n<p>mysql_secure_installation<\/p>\n<p>Master<\/p>\n<p>Add below lines on the mysql<\/p>\n<p>vi \/etc\/my.cnf<\/p>\n<p>[server]<br \/>\n# add follows in [server] section : get binary logs<br \/>\nlog-bin=mysql-bin<br \/>\n# define uniq server ID<br \/>\nserver-id=101<\/p>\n<p>Restart the mariadb service<\/p>\n<p>systemctl restart mariadb.service<\/p>\n<p>mysql -u root -p<\/p>\n<p>Enter password:<\/p>\n<p>Welcome to the MariaDB monitor. Commands end with ; or \\g.<br \/>\nYour MariaDB connection id is 9<br \/>\nServer version: 10.2.8-MariaDB-log MariaDB Server<\/p>\n<p>Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;\\h&#8217; for help. Type &#8216;\\c&#8217; to clear the current input statement.<\/p>\n<p># create user (set any password for &#8216;password&#8217; section)<\/p>\n<p>MariaDB [(none)]&gt; grant replication slave on *.* to replication@&#8217;%&#8217; identified by &#8216;P@assword&#8217;;<\/p>\n<p>Query OK, 0 rows affected (0.00 sec)<br \/>\nMariaDB [(none)]&gt; flush privileges;<\/p>\n<p>Query OK, 0 rows affected (0.00 sec)<br \/>\nMariaDB [(none)]&gt; exit<\/p>\n<p>Bye<\/p>\n<p>Slave<\/p>\n<p>Add below lines on the mysql on the slave server<\/p>\n<p>vi \/etc\/my.cnf<\/p>\n<p>slave node<br \/>\n[server]<br \/>\n# add follows in [server] section : get binary logs<\/p>\n<p>log-bin=mysql-bin<br \/>\n# define server ID (different one from Master Host)<\/p>\n<p>server-id=102<br \/>\n# read only<\/p>\n<p>read_only=1<br \/>\n# define own hostname<br \/>\nreport-host=slaveserver<\/p>\n<p>Restart the mariadb service<br \/>\nsystemctl restart mariadb.service<\/p>\n<p>Get Dump-Data on Master Host server<\/p>\n<p>mysql -u root -p<\/p>\n<p>Enter password:<\/p>\n<p>Welcome to the MariaDB monitor. Commands end with ; or \\g.<br \/>\nYour MariaDB connection id is 10<br \/>\nServer version: 10.2.8-MariaDB-log MariaDB Server<\/p>\n<p>Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.<\/p>\n<p>Type &#8216;help;&#8217; or &#8216;\\h&#8217; for help. Type &#8216;\\c&#8217; to clear the current input statement.<\/p>\n<p># lock all tables<\/p>\n<p>MMariaDB [(none)]&gt; flush tables with read lock;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>MariaDB [(none)]&gt; show master status;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n| mysql-bin.000001 | 541 | | |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+<br \/>\n1 row in set (0.00 sec)<\/p>\n<p>mysqldump -u root -p &#8211;all-databases &#8211;lock-all-tables &#8211;events &gt; mysql_dump.sql<\/p>\n<p>unlock the tables on the master server<\/p>\n<p>Enter password:<br \/>\n# back to the remained window and unlock<\/p>\n<p>MariaDB [(none)]&gt; unlock tables;<\/p>\n<p>Query OK, 0 rows affected (0.00 sec)<br \/>\nMariaDB [(none)]&gt; exit<\/p>\n<p>Bye<\/p>\n<p>scp mysql_dump.sql dev01@ec2-13-127-218-218.ap-south-1.compute.amazonaws.com:\/tmp\/<\/p>\n<p>Go to the Slave Host.<\/p>\n<p>import dump from Master Host<\/p>\n<p>[root@ip-172-31-25-39 ~]# mysql -u root -p &lt; \/tmp\/mysql_dump.sql<br \/>\nEnter password:<\/p>\n<p>Configure replication settings on Slave Host. It&#8217;s OK all, make sure the settings work normally to create databases on Master Host.<br \/>\n# import dump from Master Host<\/p>\n<p>mysql -u root -p<\/p>\n<p>CHANGE MASTER TO MASTER_HOST=&#8217;13.127.203.148&#8242;, MASTER_USER=&#8217;replication&#8217;, MASTER_PASSWORD=&#8217;P@assword&#8217;, MASTER_LOG_FILE=&#8217;| mysql-bin.000001&#8242;, MASTER_LOG_POS=541;<\/p>\n<p>MariaDB [(none)]&gt; start slave;<\/p>\n<p>Query OK, 0 rows affected (0.00 sec)<br \/>\n# show status<\/p>\n<p>MariaDB [(none)]&gt; show slave status\\G<\/p>\n<p>asterA has the following error in show slave status:<\/p>\n<p>Last_IO_Errno: 1236<br \/>\nLast_IO_Error: Got fatal error 1236 from master when reading data from binary log: \u2018Could not find first log file name in binary log index file\u2019<\/p>\n<p>Solution:<\/p>\n<p>Slave: stop slave;<\/p>\n<p>Master: flush logs<\/p>\n<p>Master: show master status; \u2014 take note of the master log file and master log position<\/p>\n<p>Slave: CHANGE MASTER TO MASTER_LOG_FILE=\u2019log-bin.00000X?, MASTER_LOG_POS=106;<\/p>\n<p>Slave: start slave;<\/p>\n<p>MariaDB [(none)]&gt; stop slave;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>MariaDB [(none)]&gt; reset slave;<br \/>\nQuery OK, 0 rows affected (0.01 sec)<\/p>\n<p>MariaDB [(none)]&gt; CHANGE MASTER TO MASTER_HOST=&#8217;13.127.203.148&#8242;, MASTER_USER=&#8217;replication&#8217;, MASTER_PASSWORD=&#8217;P@assword&#8217;, MASTER_LOG_FILE=&#8217;| mysql-bin.000005&#8242;, MASTER_LOG_POS=245;<br \/>\nQuery OK, 0 rows affected (0.01 sec)<\/p>\n<p>MariaDB [(none)]&gt; start slave;<br \/>\nQuery OK, 0 rows affected (0.00 sec)<\/p>\n<p>MariaDB [(none)]&gt; show slave status\\G ;<\/p>\n<p>&nbsp;<\/p>\n<pre>show binary logs ;<\/pre>\n<pre>&gt;for f in $(cat mysqld-bin.index); do test -f $f || echo \"Not found $f\" ; done;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MARIADB MASTER SLAVE<\/p>\n<p>Install on both master and slave<\/p>\n<p>yum install mariadb-server mariadb -y<\/p>\n<p>systemctl enable mariadb<\/p>\n<p>systemctl start mariadb.service<\/p>\n<p>mysql_secure_installation<\/p>\n<p>Master<\/p>\n<p>Add below lines on the mysql<\/p>\n<p>vi \/etc\/my.cnf<\/p>\n<p>[server] # add follows in [server] section : get binary logs log-bin=mysql-bin # define uniq server ID server-id=101<\/p>\n<p>Restart the mariadb service<\/p>\n<p>systemctl restart mariadb.service<\/p>\n<p> [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[72],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7284"}],"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=7284"}],"version-history":[{"count":3,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7284\/revisions"}],"predecessor-version":[{"id":7287,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/7284\/revisions\/7287"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}