{"id":3859,"date":"2020-07-10T15:50:59","date_gmt":"2020-07-10T07:50:59","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=3859"},"modified":"2022-05-25T12:02:56","modified_gmt":"2022-05-25T04:02:56","slug":"mysql-mysql-master-slave-setting-mysql-%e4%b8%bb%e5%be%9e%e8%a8%ad%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=3859","title":{"rendered":"[ Mysql ] &#8211; Mysql Master Slave Setting Mysql \u4e3b\u5f9e\u8a2d\u5b9a"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u7576\u4f60\u7684mysql\u6548\u80fd\u4f4e\u843d\u7684\u6642\u5019\u9664\u4e86\u4fee\u6539\u8a2d\u5b9a\u6a94\u4e4b\u5916\uff0c\u6700\u76f4\u63a5\u597d\u7528\u7684\u65b9\u6cd5\u5c31\u662f\u8b80\u5beb\u5206\u96e2\uff0c\u8a2d\u5b9a\u7684\u65b9\u5f0f\u4e5f\u9084\u7b97\u7c21\u55ae\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.webteach.tw\/?p=3859#a\">Mysql Master \u7aef 192.168.1.33<\/a><\/li><li><a href=\"https:\/\/www.webteach.tw\/?p=3859#b\">Mysql Slave \u7aef<\/a><\/li><li><a href=\"https:\/\/www.webteach.tw\/?p=3859#c\">\u91cd\u555f mysql<\/a><\/li><li><a href=\"https:\/\/www.webteach.tw\/?p=3859#d\">\u9632\u706b\u7246<\/a><\/li><\/ul>\n\n\n\n<a name=\"a\"><\/a><h2>Mysql Master \u7aef 192.168.1.33<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u8a2d\u5b9a\u6a94<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728[mysqld]\u4e0b\u65b9\u65b0\u589e\u4ee5\u4e0b\u8cc7\u8a0a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server-id = 1\nlog_bin = \/var\/log\/mysql\/mysql-bin.log\nlog_bin_index =\/var\/log\/mysql\/mysql-bin.log.index\nrelay_log = \/var\/log\/mysql\/mysql-relay-bin\nrelay_log_index = \/var\/log\/mysql\/mysql-relay-bin.index<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u555f mysql<br>\u6307\u4ee4\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service mysql restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5165 mysql \u5275\u5efa\u5e33\u865f\u7d66slave\u540c\u6b65\u7528<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'account'@'ip' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON . TO 'account'@'ip';\nflush privileges;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b master \u8a0a\u606f<br>\u6307\u4ee4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW MASTER STATUS\\G<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">File: mysql-bin.000001<br>Position: 245<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9019\u5169\u500b\u503c\u8a2dslave\u6703\u7528\u5230<\/p>\n\n\n\n<a name=\"b\"><\/a><h2>Mysql Slave \u7aef<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u8a2d\u5b9a\u6a94<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728[mysqld]\u4e0b\u65b9\u65b0\u589e\u4ee5\u4e0b\u8cc7\u8a0a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server-id = 2\nlog_bin = \/var\/log\/mysql\/mysql-bin.log\nlog_bin_index =\/var\/log\/mysql\/mysql-bin.log.index\nrelay_log = \/var\/log\/mysql\/mysql-relay-bin\nrelay_log_index = \/var\/log\/mysql\/mysql-relay-bin.index<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u555f mysql<br>\u6307\u4ee4\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service mysql restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5165 mysql \u52a0\u5165\u540c\u6b65\u8a2d\u5b9a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CHANGE MASTER TO MASTER_HOST ='192.168.1.33', MASTER_USER ='account', MASTER_PASSWORD ='password', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 245;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">CHANGE MASTER TO MASTER_HOST =&#8217;\u4e3b\u8cc7\u6599\u5eabIP&#8217;, MASTER_USER =&#8217;\u4e3b\u8cc7\u6599\u5eab\u525b\u65b0\u589e\u8981\u4f86\u540c\u6b65\u7684\u5e33\u865f&#8217;, MASTER_PASSWORD =&#8217;abcdef&#8217;, MASTER_LOG_FILE = &#8216;\u4e3b\u8cc7\u6599\u5eab\u7684\u4e8c\u9032\u5236\u6a94&#8217;, MASTER_LOG_POS = \u8a18\u9304\u6a94\u4f4d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>start slave;<\/code><\/pre>\n\n\n\n<a name=\"c\"><\/a><h2>\u91cd\u555f mysql<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6307\u4ee4\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service mysql restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u767b\u5165 mysql \u67e5\u770b slave \u8a0a\u606f\uff0c\u5982\u679c\u6709\u932f\u8aa4\u7684\u8a71\u8a0a\u606f\u6703\u5728\u9019\u908a\u51fa\u73fe<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>show slave status\\G<\/code><\/pre>\n\n\n\n<a name=\"d\"><\/a><h2>\u9632\u706b\u7246<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">AWS \u5b89\u5168\u7d44 \u5165\u7ad9 3306 192.168.1.33<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e00\u822c\u4e3b\u6a5f\u5c31\u662f iptable \u91dd\u5c0d 192.168.1.33 \u958b3306 port<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2020-07-10<br>\u82e5slave\u7aef\u6709error\uff0c\u901a\u5e38\u662f\u8cc7\u6599\u4e0d\u4e00\u81f4\u6642\uff0cmaster\u7aef\u7684 Position \u5c31\u6703\u6709\u7570\u52d5\uff0c\u6b64\u6642 slave\u7aef\u5c31\u8981\u91cd\u65b0\u5efa\u7acb\u540c\u6b65\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stop slave;\nCHANGE MASTER TO MASTER_HOST ='192.168.1.33', MASTER_USER ='account', MASTER_PASSWORD ='password', MASTER_LOG_FILE = 'mysql-bin.000001', MASTER_LOG_POS = 245;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">CHANGE MASTER TO MASTER_HOST =&#8217;\u4e3b\u8cc7\u6599\u5eabIP&#8217;, MASTER_USER =&#8217;\u4e3b\u8cc7\u6599\u5eab\u525b\u65b0\u589e\u8981\u4f86\u540c\u6b65\u7684\u5e33\u865f&#8217;, MASTER_PASSWORD =&#8217;abcdef&#8217;, MASTER_LOG_FILE = &#8216;\u4e3b\u8cc7\u6599\u5eab\u7684\u4e8c\u9032\u5236\u6a94&#8217;, MASTER_LOG_POS = \u65b0\u7684\u8a18\u9304\u6a94\u4f4d\u7f6e;<br>start slave;<br><br>\u6700\u5f8c\u518d\u91cd\u555f slave mysql<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service mysql restart;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2022-05-24<br>\u505c\u6b62\u540c\u6b65\u5f8c\u7684\u7b2c\u4e8c\u7a2e\u8655\u7406\u65b9\u6cd5<br><br><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Master<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>show master status\\g<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br>| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |<br>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br>| mysql-bin.013632 | 23873964 | | | |<br>+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Slave<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>show slave status\\g\n\/\/\u6703\u51fa\u73fe\u70ba\u4ec0\u9ebc\u505c\u6b62\u540c\u6b65\u7684\u932f\u8aa4\u8a0a\u606f\n\nstop slave;\n\nchange master to master_log_file=\u2019mysql-bin.013632\u2032, master_log_pos=23873964;\n\nstart slave;\n\nshow slave status\\g<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7576\u4f60\u7684mysql\u6548\u80fd\u4f4e\u843d\u7684\u6642\u5019\u9664\u4e86\u4fee\u6539\u8a2d\u5b9a\u6a94\u4e4b\u5916\uff0c\u6700\u76f4\u63a5\u597d\u7528\u7684\u65b9\u6cd5\u5c31\u662f\u8b80\u5beb\u5206\u96e2\uff0c\u8a2d\u5b9a\u7684\u65b9\u5f0f\u4e5f\u9084\u7b97\u7c21\u55ae\u3002<\/p>\n","protected":false},"author":1,"featured_media":1867,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[370,385,402,517,652],"class_list":["post-3859","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-linux","tag-master","tag-mysql","tag-slave","tag-652","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3859"}],"version-history":[{"count":4,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3859\/revisions"}],"predecessor-version":[{"id":5252,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/3859\/revisions\/5252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/1867"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}