{"id":79,"date":"2020-03-19T09:47:08","date_gmt":"2020-03-19T08:47:08","guid":{"rendered":"https:\/\/www.funkgui.it\/?p=79"},"modified":"2024-10-23T15:01:49","modified_gmt":"2024-10-23T13:01:49","slug":"mysql-replication","status":"publish","type":"post","link":"https:\/\/www.funkgui.it\/index.php\/mysql-replication\/","title":{"rendered":"MySQL replication"},"content":{"rendered":"\r\n<p>Appunti veloci senza troppi commenti&#8230;.<\/p>\r\n\r\n\r\n\r\n<p>Sul MASTER<\/p>\r\n\r\n\r\n\r\n<p>skip-innodb<br \/>default-storage-engine = MyISAM<\/p>\r\n\r\n\r\n\r\n<p>Si NON AMO INNODB!<\/p>\r\n\r\n\r\n\r\n<p>server-id=1<\/p>\r\n\r\n\r\n\r\n<p>log-bin = mysql-bin<br \/>binlog-ignore-db = &#8220;mysql&#8221;<br \/>binlog-ignore-db = &#8220;sys&#8221;<br \/>binlog-ignore-db = &#8220;performance_schema&#8221;<\/p>\r\n\r\n\r\n\r\n<p>systemctl restart mysql.service<\/p>\r\n\r\n\r\n\r\n<p>grant replication slave on <em>.<\/em> TO &#8216;slaveuser&#8217;@&#8217;%&#8217; identified by &#8216;xxxxxxxxxxxxxxx&#8217;;<br \/>SE mysql \u00e8 versione 8<br \/>CREATE USER &#8216;thesalveusername&#8217;@&#8217;%&#8217; identified by &#8216;XXXXX&#8217;;<br \/>grant replication slave on <em>.<\/em> TO &#8216;thesalveusername&#8217;@&#8217;%&#8217;;<\/p>\r\n\r\n\r\n\r\n<p>FLUSH TABLES WITH READ LOCK;<\/p>\r\n\r\n\r\n\r\n<p>creare i dump dei db e copiarli sulla macchina slave<\/p>\r\n\r\n\r\n\r\n<p>SHOW MASTER STATUS;<br \/>ci dar\u00e0 le informazioni sul nome file di log e sulla posizione da cui far partire la replicazione<\/p>\r\n\r\n\r\n\r\n<p>UNLOCK TABLES;<\/p>\r\n\r\n\r\n\r\n<p>Sullo SLAVE<\/p>\r\n\r\n\r\n\r\n<p>skip-innodb<br \/>default-storage-engine = MyISAM<\/p>\r\n\r\n\r\n\r\n<p>server-id = 2<\/p>\r\n\r\n\r\n\r\n<p>SLAVE STOP; <br \/>CHANGE MASTER TO MASTER_HOST=&#8217;192.168.1.54&#8242;,<br \/>MASTER_PORT=3306,<br \/>MASTER_USER=&#8217;thesalveusername&#8217;,<br \/>MASTER_PASSWORD=&#8217;ddddddddd&#8217;;<br \/>START SLAVE;<br \/>SHOW SLAVE STATUS\\G<\/p>\r\n\r\n\r\n\r\n<p>on mysql8<\/p>\r\n\r\n\r\n\r\n<p>STOP SLAVE;<br \/>CHANGE MASTER TO MASTER_HOST=&#8217;30.31.32.33&#8242;,<br \/>MASTER_PORT=3306,<br \/>MASTER_USER=&#8217;thesalveusername&#8217;,<br \/>MASTER_PASSWORD=&#8217;xxxxxxxx&#8217;;<br \/>START SLAVE;<br \/>SHOW SLAVE STATUS\\G<\/p>\r\n\r\n\r\n\r\n<p>CHANGE MASTER TO MASTER_HOST=&#8217;30.31.32.33&#8242;,<br \/>MASTER_PORT=3306,<br \/>MASTER_USER=&#8217;thesalveusername&#8217;,<br \/>MASTER_PASSWORD=&#8217;dddddddd&#8217;, MASTER_LOG_FILE=&#8217;mysql-bin.000001&#8242;, MASTER_LOG_POS= 155;<br \/>START SLAVE;<br \/>SHOW SLAVE STATUS\\G<\/p>\r\n\r\n\r\n\r\n<p>Se lo slave non partisse utilizzare nella shell mysql il comando:<\/p>\r\n\r\n\r\n\r\n<p><code>slave reset<\/code><\/p>\r\n\r\n\r\n\r\n<p>Se la macchina dovessere essere un clone ricordarsi di eliminare il file \/var\/lib\/mysql\/auto.cnf in modo che i server abbiano UUID differente.<\/p>\r\n<p>Nel caso debba essere necessario modificare l&#8217;utente o l&#8217;ip dal quale lo slave si connette:<\/p>\r\n<p>DAL MASTER:<\/p>\r\n<p>select host,user from mysql.user;<br \/>RENAME USER &#8216;slaveuser&#8217;@&#8217;9.9.9.9&#8217; TO &#8216;slaveuser&#8217;@&#8217;5.5.5.5&#8217;;<br \/>revoke replication slave on . FROM &#8216;slaveuser&#8217;@&#8217;9.9.9.9&#8217;;<br \/>grant replication slave on . TO &#8216;slaveuser&#8217;@&#8217;5.5.5.5&#8217;;<\/p>\r\n<p>se fosse necessario rifare il dump per ripristinare una replica:<\/p>\r\n<p>mysqldump &#8211;routines &#8211;triggers &#8211;source-data=1 -B &#8212;ELENCO DEI DB SEPARATO DA SPAZI&#8212; | gzip -1 &gt; \/tmp\/master-$(date +%Y-%m-%d).sql.gz<\/p>\r\n<p>e poi sullo slave:<\/p>\r\n<p>stop slave; (o reset slave;)<\/p>\r\n<p>poi si importa il dump<\/p>\r\n<p>e poi start slave;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Appunti veloci senza troppi commenti&#8230;. Sul MASTER skip-innodbdefault-storage-engine = MyISAM Si NON AMO INNODB! server-id=1 log-bin = mysql-binbinlog-ignore-db = &#8220;mysql&#8221;binlog-ignore-db = &#8220;sys&#8221;binlog-ignore-db = &#8220;performance_schema&#8221; systemctl restart mysql.service grant replication slave on . TO &#8216;slaveuser&#8217;@&#8217;%&#8217; identified by &#8216;xxxxxxxxxxxxxxx&#8217;;SE mysql \u00e8 versione 8CREATE USER &#8216;thesalveusername&#8217;@&#8217;%&#8217; identified by &#8216;XXXXX&#8217;;grant replication slave on . TO &#8216;thesalveusername&#8217;@&#8217;%&#8217;; FLUSH TABLES WITH [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4],"tags":[],"class_list":["post-79","post","type-post","status-publish","format-standard","hentry","category-generico","category-linux"],"_links":{"self":[{"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/posts\/79","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/comments?post=79"}],"version-history":[{"count":2,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions"}],"predecessor-version":[{"id":117,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/posts\/79\/revisions\/117"}],"wp:attachment":[{"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/media?parent=79"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/categories?post=79"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.funkgui.it\/index.php\/wp-json\/wp\/v2\/tags?post=79"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}