{"id":202,"date":"2016-05-21T16:33:59","date_gmt":"2016-05-21T08:33:59","guid":{"rendered":"http:\/\/www.lixiaodong.com\/?p=202"},"modified":"2025-03-06T11:04:57","modified_gmt":"2025-03-06T03:04:57","slug":"mysql%e8%ae%be%e7%bd%ae%e4%b8%bb%e4%bb%8e%e5%a4%8d%e5%88%b6","status":"publish","type":"post","link":"https:\/\/www.lixiaodong.com\/?p=202","title":{"rendered":"mysql\u8bbe\u7f6e\u4e3b\u4ece\u590d\u5236"},"content":{"rendered":"<p>\u51c6\u59072\u53f0\u670d\u52a1\u5668\uff0c\u670d\u52a1\u56681\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u670d\u52a1\u56682\u4f5c\u4e3a\u4ece\u6570\u636e\u5e93\u3002<\/p>\n<p>1.\u4fee\u6539\u4e3b\u5e93\u7684\u914d\u7f6e<br \/>\n\u8fd9\u91cc\u4f7f\u7528\u7684\u662fubuntu\u4e0b\u7684MYSQL\uff0c\u7248\u672c\u4e3a5.6.30\uff0c\u4f7f\u7528apt-get\u65b9\u5f0f\u5b89\u88c5\u3002<br \/>\n1)\u9996\u5148\u4fee\u6539\/etc\/mysql\/conf.d\/mysql.cnf<br \/>\n[mysqld]<br \/>\nbind-address = 0.0.0.0<br \/>\nlog-bin=mysql-bin<br \/>\nserver-id=1<br \/>\n2)\u7136\u540e\u4fee\u6539\/etc\/mysql\/mysql.conf.d\/mysqld.cnf\u3002<br \/>\nbind-address            = 0.0.0.0<br \/>\n\u6ce8\u610f\uff1a\u5c06\u4e0a\u97622\u4e2a\u6587\u4ef6\u7684bind-address\u90fd\u8bbe\u7f6e\u62100.0.0.0\uff0c\u662f\u4e3a\u4e86\u8ba9\u4ece\u5e93\u80fd\u591f\u8fde\u63a5\u4e3b\u5e93\u3002<br \/>\n3)\u91cd\u542fmysql\u4f7f\u4ee5\u4e0a\u4fee\u6539\u751f\u6548: service mysql restart<\/p>\n<p>2.\u5728\u4e3b\u6570\u636e\u5e93\u521b\u5efa\u7528\u6237<br \/>\nCREATE USER &#8216;repl&#8217;@&#8217;10.99.%.%&#8217; IDENTIFIED BY &#8216;slavepassword&#8217;;<br \/>\nGRANT REPLICATION SLAVE ON *.* TO &#8216;repl&#8217;@&#8217;10.99.%.%&#8217;;<br \/>\n\u4ee5\u4e0aip\u5730\u5740\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8bbe\u7f6e\u3002<\/p>\n<p>3.\u83b7\u53d6\u4e3b\u6570\u636e\u5e93\u590d\u5236\u6587\u4ef6\u540d\u79f0\u548c\u590d\u5236\u70b9\u4f4d\u7f6e<br \/>\n\u9996\u5148\u7ed9\u6570\u636e\u5e93\u4e0a\u9501\uff0c\u9632\u6b62\u6570\u636e\u5199\u5165\uff1aFLUSH TABLES WITH READ LOCK;<br \/>\n\u83b7\u53d6\u4e3b\u5e93\u72b6\u6001\uff1aSHOW MASTER STATUS;<br \/>\n\u5f97\u5230File\u548cPotision2\u4e2a\u5b57\u6bb5\u7684\u503c\uff1a<br \/>\n+&#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 \/>\n| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |<br \/>\n+&#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 \/>\n| mysql-bin.000002 |      120 |              |                  |                   |<br \/>\n+&#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 \/>\n\u8bb0\u4e0b2\u4e2a\u503c\uff0c\u7136\u540e\u5c31\u53ef\u4ee5\u89e3\u9501\u4e86\uff1aUNLOCK TABLES;<\/p>\n<p>4.\u914d\u7f6e\u4ece\u6570\u636e\u5e93<br \/>\n1)\u7f16\u8f91\u4ece\u6570\u636e\u5e93\u7684\/etc\/mysql\/conf.d\/mysql.cnf<br \/>\n[mysqld]<br \/>\nserver-id=2<br \/>\n\u6ce8\u610f\uff1a\u5982\u679c\u53ea\u60f3\u590d\u5236\u67d01\u4e2a\u5e93\uff0c\u8fd8\u8981\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\u9879<br \/>\nreplicate-wild-do-table=dbname.%<br \/>\n\u8fd9\u91cc\u7684dbname\u662f\u60f3\u590d\u5236\u7684\u4e3b\u5e93\u7684\u67d0\u4e00\u4e2a\u6570\u636e\u5e93\u7684\u540d\u5b57\u3002<\/p>\n<p>2)\u91cd\u542fmysql: service mysql restart<\/p>\n<p>3)\u8bbe\u7f6e\u590d\u5236\u914d\u7f6e:<br \/>\nCHANGE MASTER TO<br \/>\n    MASTER_HOST=&#8217;10.99.0.10&#8242;,<br \/>\n    MASTER_USER=&#8217;repl&#8217;,<br \/>\n    MASTER_PASSWORD=&#8217;slavepassword&#8217;,<br \/>\n    MASTER_LOG_FILE=&#8217;mysql-bin.000002&#8242;,<br \/>\n    MASTER_LOG_POS=120;<br \/>\n\u8fd9\u91ccMASTER_HOST\u662f\u4e3b\u5e93\u7684ip\u5730\u5740\uff0c\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u6307\u5b9a\u3002<br \/>\n4)\u542f\u52a8\u590d\u5236\uff1aSTART SLAVE;<\/p>\n<p>5.\u8bd5\u9a8c<br \/>\n\u4e3b\u5e93\u4e0a\u65b0\u5efa\u4e00\u4e2a\u6570\u636e\u5e93: create database hello<br \/>\n\u7a0d\u7b49\u4e00\u4f1a\u513f\uff0c\u5728\u4ece\u5e93\u4e0a\u4f1a\u770b\u5230\u591a\u4e86hello\u6570\u636e\u5e93\uff0c\u8bf4\u660e\u4ee5\u4e0a\u914d\u7f6e\u6210\u529f\u3002<br \/>\n\u53ef\u4ee5\u7528\u4ee5\u4e0b\u547d\u4ee4\u5728\u4ece\u5e93\u4e0a\u67e5\u770b\u590d\u5236\u7684\u72b6\u6001\uff1ashow slave status;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u51c6\u59072\u53f0\u670d\u52a1\u5668\uff0c\u670d\u52a1\u56681\u4f5c\u4e3a\u4e3b\u6570\u636e\u5e93\uff0c\u670d\u52a1\u56682\u4f5c\u4e3a\u4ece\u6570\u636e\u5e93\u3002 1.\u4fee\u6539\u4e3b\u5e93\u7684\u914d\u7f6e &hellip; <a href=\"https:\/\/www.lixiaodong.com\/?p=202\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202"}],"version-history":[{"count":8,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":214,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions\/214"}],"wp:attachment":[{"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lixiaodong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}