{"id":174449,"date":"2024-11-07T21:57:24","date_gmt":"2024-11-07T13:57:24","guid":{"rendered":"https:\/\/server.hk\/cnblog\/174449\/"},"modified":"2024-11-07T21:57:25","modified_gmt":"2024-11-07T13:57:25","slug":"%e5%a6%82%e4%bd%95%e9%80%b2%e8%a1%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e5%84%aa%e5%8c%96%ef%bc%9f-%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e4%bb%80","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/174449\/","title":{"rendered":"\u5982\u4f55\u9032\u884c\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u512a\u5316\uff1f (\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u4ec0\u9ebc\u610f\u601d)"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e9%80%b2%e8%a1%8c%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e5%84%aa%e5%8c%96%ef%bc%9f-hJwmJmojrP\">\u5982\u4f55\u9032\u884c\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u512a\u5316\uff1f<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6574\u9ad4\u8868\u73fe\u81f3\u95dc\u91cd\u8981\u3002\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\u548c\u6578\u64da\u91cf\u7684\u64f4\u5927\uff0c\u55ae\u4e00\u6578\u64da\u5eab\u7684\u8b80\u5beb\u8ca0\u8f09\u53ef\u80fd\u6703\u6210\u70ba\u74f6\u9838\u3002\u70ba\u4e86\u89e3\u6c7a\u9019\u4e00\u554f\u984c\uff0c\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u6280\u8853\u61c9\u904b\u800c\u751f\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u7684\u6982\u5ff5\u53ca\u5176\u512a\u5316\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%e6%98%af%e4%bb%80%e9%ba%bc%ef%bc%9f-hJwmJmojrP\">\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u662f\u4ec0\u9ebc\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u662f\u4e00\u7a2e\u67b6\u69cb\u8a2d\u8a08\uff0c\u65e8\u5728\u5c07\u6578\u64da\u5eab\u7684\u8b80\u53d6\u64cd\u4f5c\u548c\u5beb\u5165\u64cd\u4f5c\u5206\u958b\u8655\u7406\u3002\u901a\u5e38\uff0c\u9019\u7a2e\u8a2d\u8a08\u6703\u6d89\u53ca\u5230\u81f3\u5c11\u5169\u500b\u6578\u64da\u5eab\u5be6\u4f8b\uff1a\u4e00\u500b\u4e3b\u6578\u64da\u5eab\uff08Master\uff09\u7528\u65bc\u8655\u7406\u5beb\u5165\u64cd\u4f5c\uff0c\u53e6\u4e00\u500b\u6216\u591a\u500b\u5f9e\u6578\u64da\u5eab\uff08Slave\uff09\u7528\u65bc\u8655\u7406\u8b80\u53d6\u64cd\u4f5c\u3002<\/p>\n<p>\u9019\u7a2e\u5206\u96e2\u7684\u4e3b\u8981\u76ee\u7684\u662f\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002\u901a\u904e\u5c07\u8b80\u53d6\u8acb\u6c42\u5206\u6563\u5230\u591a\u500b\u5f9e\u6578\u64da\u5eab\u4e0a\uff0c\u53ef\u4ee5\u6e1b\u5c11\u4e3b\u6578\u64da\u5eab\u7684\u8ca0\u64d4\uff0c\u5f9e\u800c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u7684\u97ff\u61c9\u901f\u5ea6\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%ef%bc%9f-hJwmJmojrP\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\uff1f<\/h2>\n<ul>\n<li><strong>\u6027\u80fd\u63d0\u5347\uff1a<\/strong>\u901a\u904e\u5c07\u8b80\u53d6\u8acb\u6c42\u5206\u6563\u5230\u591a\u500b\u5f9e\u6578\u64da\u5eab\u4e0a\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u53ef\u64f4\u5c55\u6027\uff1a<\/strong>\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\uff0c\u53ef\u4ee5\u8f15\u9b06\u6dfb\u52a0\u66f4\u591a\u7684\u5f9e\u6578\u64da\u5eab\u4f86\u61c9\u5c0d\u589e\u9577\u7684\u8b80\u53d6\u9700\u6c42\u3002<\/li>\n<li><strong>\u6545\u969c\u5bb9\u932f\uff1a<\/strong>\u5982\u679c\u4e3b\u6578\u64da\u5eab\u51fa\u73fe\u6545\u969c\uff0c\u7cfb\u7d71\u4ecd\u7136\u53ef\u4ee5\u901a\u904e\u5f9e\u6578\u64da\u5eab\u63d0\u4f9b\u8b80\u53d6\u670d\u52d9\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%be%e6%95%b8%e6%93%9a%e5%ba%ab%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%ef%bc%9f-hJwmJmojrP\">\u5982\u4f55\u5be6\u73fe\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\uff1f<\/h2>\n<p>\u5be6\u73fe\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u901a\u5e38\u6d89\u53ca\u4ee5\u4e0b\u5e7e\u500b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e8%a8%ad%e8%a8%88%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9e%b6%e6%a7%8b-hJwmJmojrP\">1. \u8a2d\u8a08\u6578\u64da\u5eab\u67b6\u69cb<\/h3>\n<p>\u9996\u5148\uff0c\u9700\u8981\u8a2d\u8a08\u4e00\u500b\u5408\u9069\u7684\u6578\u64da\u5eab\u67b6\u69cb\u3002\u9019\u901a\u5e38\u5305\u62ec\u4e00\u500b\u4e3b\u6578\u64da\u5eab\u548c\u591a\u500b\u5f9e\u6578\u64da\u5eab\u3002\u4e3b\u6578\u64da\u5eab\u8ca0\u8cac\u6240\u6709\u7684\u5beb\u5165\u64cd\u4f5c\uff0c\u800c\u5f9e\u6578\u64da\u5eab\u5247\u7528\u65bc\u8655\u7406\u8b80\u53d6\u8acb\u6c42\u3002<\/p>\n<h3 id=\"2-%e9%85%8d%e7%bd%ae%e6%95%b8%e6%93%9a%e5%ba%ab%e8%a4%87%e8%a3%bd-hJwmJmojrP\">2. \u914d\u7f6e\u6578\u64da\u5eab\u8907\u88fd<\/h3>\n<p>\u4e3b\u6578\u64da\u5eab\u7684\u6578\u64da\u9700\u8981\u5b9a\u671f\u8907\u88fd\u5230\u5f9e\u6578\u64da\u5eab\u3002\u9019\u53ef\u4ee5\u901a\u904e\u6578\u64da\u5eab\u7684\u5167\u5efa\u8907\u88fd\u529f\u80fd\u4f86\u5be6\u73fe\u3002\u4f8b\u5982\uff0c\u5728MySQL\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e8c\u9032\u5236\u65e5\u8a8c\uff08Binary Log\uff09\u4f86\u5be6\u73fe\u4e3b\u5f9e\u8907\u88fd\u3002<\/p>\n<pre><code>CHANGE MASTER TO\n    MASTER_HOST='\u4e3b\u6578\u64da\u5eabIP',\n    MASTER_USER='\u8907\u88fd\u7528\u6236',\n    MASTER_PASSWORD='\u5bc6\u78bc',\n    MASTER_LOG_FILE='mysql-bin.000001',\n    MASTER_LOG_POS=107;\nSTART SLAVE;<\/code><\/pre>\n<h3 id=\"3-%e5%af%a6%e7%8f%be%e8%ae%80%e5%af%ab%e5%88%86%e6%b5%81-hJwmJmojrP\">3. \u5be6\u73fe\u8b80\u5beb\u5206\u6d41<\/h3>\n<p>\u5728\u61c9\u7528\u5c64\u9762\uff0c\u9700\u8981\u5be6\u73fe\u8b80\u5beb\u5206\u6d41\u7684\u908f\u8f2f\u3002\u9019\u610f\u5473\u8457\u5728\u9032\u884c\u6578\u64da\u5eab\u64cd\u4f5c\u6642\uff0c\u61c9\u6839\u64da\u64cd\u4f5c\u985e\u578b\uff08\u8b80\u53d6\u6216\u5beb\u5165\uff09\u9078\u64c7\u76f8\u61c9\u7684\u6578\u64da\u5eab\u3002\u4f8b\u5982\uff0c\u4f7f\u7528ORM\u6846\u67b6\u6642\uff0c\u53ef\u4ee5\u6839\u64da\u64cd\u4f5c\u985e\u578b\u81ea\u52d5\u9078\u64c7\u4e3b\u6216\u5f9e\u6578\u64da\u5eab\u3002<\/p>\n<pre><code>if (operation == 'read') {\n    \/\/ \u9023\u63a5\u5230\u5f9e\u6578\u64da\u5eab\n} else {\n    \/\/ \u9023\u63a5\u5230\u4e3b\u6578\u64da\u5eab\n}<\/code><\/pre>\n<h3 id=\"4-%e7%9b%a3%e6%8e%a7%e5%92%8c%e8%aa%bf%e6%95%b4-hJwmJmojrP\">4. \u76e3\u63a7\u548c\u8abf\u6574<\/h3>\n<p>\u5be6\u65bd\u8b80\u5beb\u5206\u96e2\u5f8c\uff0c\u6301\u7e8c\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u6839\u64da\u5be6\u969b\u7684\u8b80\u5beb\u8ca0\u8f09\uff0c\u53ef\u80fd\u9700\u8981\u8abf\u6574\u5f9e\u6578\u64da\u5eab\u7684\u6578\u91cf\u6216\u914d\u7f6e\uff0c\u4ee5\u78ba\u4fdd\u7cfb\u7d71\u7684\u6700\u4f73\u6027\u80fd\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-hJwmJmojrP\">\u7d50\u8ad6<\/h2>\n<p>\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u662f\u4e00\u7a2e\u6709\u6548\u7684\u512a\u5316\u6280\u8853\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u7cfb\u7d71\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002\u901a\u904e\u5408\u7406\u7684\u67b6\u69cb\u8a2d\u8a08\u3001\u914d\u7f6e\u8907\u88fd\u3001\u5be6\u73fe\u8b80\u5beb\u5206\u6d41\u4ee5\u53ca\u6301\u7e8c\u76e3\u63a7\uff0c\u4f01\u696d\u53ef\u4ee5\u6709\u6548\u5730\u61c9\u5c0d\u4e0d\u65b7\u589e\u9577\u7684\u6578\u64da\u9700\u6c42\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u9700\u6c42\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\uff0c\u4ee5\u7372\u5f97\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u6578\u64da\u5eab\u8b80\u5beb\u5206\u96e2\u7684\u6982\u5ff5\u53ca\u5176\u512a\u5316\u65b9\u6cd5\uff0c\u63d0\u9ad8\u7cfb\u7d71\u6027\u80fd\u8207\u53ef\u64f4\u5c55\u6027\uff0c\u5be6\u73fe\u9ad8\u6548\u6578\u64da\u8655\u7406\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-174449","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174449","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=174449"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174449\/revisions"}],"predecessor-version":[{"id":174450,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/174449\/revisions\/174450"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=174449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=174449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=174449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}