{"id":76462,"date":"2024-10-16T06:52:14","date_gmt":"2024-10-15T22:52:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76462\/"},"modified":"2024-10-16T06:52:14","modified_gmt":"2024-10-15T22:52:14","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%90%8c%e6%ad%a5%e5%af%a6%e4%be%8b%e6%bc%94%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76462\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u5be6\u4f8b\u6f14\u793a"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%90%8c%e6%ad%a5%e5%af%a6%e4%be%8b%e6%bc%94%e7%a4%ba-lOENGFWEMn\">MySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u5be6\u4f8b\u6f14\u793a<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u9ad8\u53ef\u7528\u6027\u548c\u6578\u64da\u4e00\u81f4\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u6578\u64da\u540c\u6b65\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u4ecb\u7d39MySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u6280\u8853\uff0c\u4e26\u901a\u904e\u5be6\u4f8b\u6f14\u793a\u5982\u4f55\u8a2d\u7f6e\u6578\u64da\u5eab\u540c\u6b65\u3002<\/p>\n<h2 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e5%90%8c%e6%ad%a5%e7%9a%84%e6%a6%82%e5%bf%b5-lOENGFWEMn\">MySQL\u6578\u64da\u5eab\u540c\u6b65\u7684\u6982\u5ff5<\/h2>\n<p>\u6578\u64da\u5eab\u540c\u6b65\u662f\u6307\u5c07\u4e00\u500b\u6578\u64da\u5eab\u4e2d\u7684\u6578\u64da\u66f4\u65b0\u5230\u53e6\u4e00\u500b\u6578\u64da\u5eab\u4e2d\uff0c\u4ee5\u78ba\u4fdd\u5169\u8005\u4e4b\u9593\u7684\u6578\u64da\u4e00\u81f4\u6027\u3002MySQL\u652f\u6301\u591a\u7a2e\u540c\u6b65\u65b9\u5f0f\uff0c\u5305\u62ec\u4e3b\u5f9e\u8907\u88fd\u3001\u96d9\u4e3b\u8907\u88fd\u548c\u7fa4\u96c6\u7b49\u3002\u9019\u4e9b\u6280\u8853\u53ef\u4ee5\u5e6b\u52a9\u4f01\u696d\u5be6\u73fe\u6578\u64da\u7684\u9ad8\u53ef\u7528\u6027\u548c\u8ca0\u8f09\u5747\u8861\u3002<\/p>\n<h2 id=\"%e4%b8%bb%e5%be%9e%e8%a4%87%e8%a3%bd-lOENGFWEMn\">\u4e3b\u5f9e\u8907\u88fd<\/h2>\n<p>\u4e3b\u5f9e\u8907\u88fd\u662fMySQL\u4e2d\u6700\u5e38\u898b\u7684\u6578\u64da\u540c\u6b65\u65b9\u5f0f\u3002\u5728\u9019\u7a2e\u6a21\u5f0f\u4e0b\uff0c\u4e00\u500b\u4e3b\u6578\u64da\u5eab\uff08Master\uff09\u8ca0\u8cac\u8655\u7406\u6240\u6709\u7684\u5beb\u5165\u64cd\u4f5c\uff0c\u800c\u4e00\u500b\u6216\u591a\u500b\u5f9e\u6578\u64da\u5eab\uff08Slave\uff09\u5247\u8ca0\u8cac\u8b80\u53d6\u64cd\u4f5c\u3002\u5f9e\u6578\u64da\u5eab\u6703\u5b9a\u671f\u5f9e\u4e3b\u6578\u64da\u5eab\u7372\u53d6\u66f4\u65b0\uff0c\u78ba\u4fdd\u6578\u64da\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e4%b8%bb%e5%be%9e%e8%a4%87%e8%a3%bd%e7%9a%84%e6%ad%a5%e9%a9%9f-lOENGFWEMn\">\u8a2d\u7f6e\u4e3b\u5f9e\u8907\u88fd\u7684\u6b65\u9a5f<\/h3>\n<ol>\n<li><strong>\u914d\u7f6e\u4e3b\u6578\u64da\u5eab<\/strong><\/li>\n<pre><code>-- \u7de8\u8f2f MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf\n[mysqld]\nserver-id=1\nlog-bin=mysql-bin\n<\/code><\/pre>\n<li><strong>\u91cd\u555f\u4e3b\u6578\u64da\u5eab<\/strong><\/li>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<li><strong>\u5275\u5efa\u8907\u88fd\u7528\u6236<\/strong><\/li>\n<pre><code>CREATE USER 'replicator'@'%' IDENTIFIED BY 'password';\nGRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';<\/code><\/pre>\n<li><strong>\u7372\u53d6\u4e3b\u6578\u64da\u5eab\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u4f4d\u7f6e<\/strong><\/li>\n<pre><code>SHOW MASTER STATUS;<\/code><\/pre>\n<li><strong>\u914d\u7f6e\u5f9e\u6578\u64da\u5eab<\/strong><\/li>\n<pre><code>-- \u7de8\u8f2f MySQL \u914d\u7f6e\u6587\u4ef6 my.cnf\n[mysqld]\nserver-id=2\n<\/code><\/pre>\n<li><strong>\u91cd\u555f\u5f9e\u6578\u64da\u5eab<\/strong><\/li>\n<pre><code>sudo systemctl restart mysql<\/code><\/pre>\n<li><strong>\u8a2d\u7f6e\u5f9e\u6578\u64da\u5eab\u9023\u63a5\u4e3b\u6578\u64da\u5eab<\/strong><\/li>\n<pre><code>CHANGE MASTER TO\nMASTER_HOST='\u4e3b\u6578\u64da\u5eabIP',\nMASTER_USER='replicator',\nMASTER_PASSWORD='password',\nMASTER_LOG_FILE='mysql-bin.000001',\nMASTER_LOG_POS=12345;<\/code><\/pre>\n<li><strong>\u555f\u52d5\u5f9e\u6578\u64da\u5eab\u7684\u8907\u88fd\u9032\u7a0b<\/strong><\/li>\n<pre><code>START SLAVE;<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e9%9b%99%e4%b8%bb%e8%a4%87%e8%a3%bd-lOENGFWEMn\">\u96d9\u4e3b\u8907\u88fd<\/h2>\n<p>\u96d9\u4e3b\u8907\u88fd\u662f\u4e00\u7a2e\u66f4\u70ba\u8907\u96dc\u7684\u540c\u6b65\u65b9\u5f0f\uff0c\u5141\u8a31\u5169\u500b\u6578\u64da\u5eab\u4e92\u70ba\u4e3b\u5f9e\uff0c\u9019\u6a23\u53ef\u4ee5\u5be6\u73fe\u66f4\u9ad8\u7684\u53ef\u7528\u6027\u548c\u8ca0\u8f09\u5747\u8861\u3002\u7136\u800c\uff0c\u9019\u7a2e\u6a21\u5f0f\u9700\u8981\u7279\u5225\u6ce8\u610f\u6578\u64da\u885d\u7a81\u7684\u8655\u7406\u3002<\/p>\n<h3 id=\"%e8%a8%ad%e7%bd%ae%e9%9b%99%e4%b8%bb%e8%a4%87%e8%a3%bd%e7%9a%84%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-lOENGFWEMn\">\u8a2d\u7f6e\u96d9\u4e3b\u8907\u88fd\u7684\u6ce8\u610f\u4e8b\u9805<\/h3>\n<ul>\n<li>\u78ba\u4fdd\u6bcf\u500b\u6578\u64da\u5eab\u90fd\u6709\u552f\u4e00\u7684server-id\u3002<\/li>\n<li>\u4f7f\u7528\u4e0d\u540c\u7684\u4e8c\u9032\u5236\u65e5\u8a8c\u6587\u4ef6\u540d\u3002<\/li>\n<li>\u8a2d\u7f6e\u9069\u7576\u7684\u885d\u7a81\u89e3\u6c7a\u7b56\u7565\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%be%a4%e9%9b%86%e6%8a%80%e8%a1%93-lOENGFWEMn\">\u7fa4\u96c6\u6280\u8853<\/h2>\n<p>MySQL\u7fa4\u96c6\u662f\u4e00\u7a2e\u9ad8\u53ef\u7528\u6027\u89e3\u6c7a\u65b9\u6848\uff0c\u5141\u8a31\u591a\u500b\u6578\u64da\u5eab\u5be6\u4f8b\u5171\u540c\u5de5\u4f5c\uff0c\u63d0\u4f9b\u6578\u64da\u7684\u5197\u9918\u548c\u8ca0\u8f09\u5747\u8861\u3002\u9019\u7a2e\u6280\u8853\u9069\u5408\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u9ad8\u6027\u80fd\u7684\u61c9\u7528\u5834\u666f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-lOENGFWEMn\">\u7e3d\u7d50<\/h2>\n<p>MySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u6280\u8853\u70ba\u4f01\u696d\u63d0\u4f9b\u4e86\u9748\u6d3b\u7684\u6578\u64da\u7ba1\u7406\u89e3\u6c7a\u65b9\u6848\u3002\u7121\u8ad6\u662f\u4e3b\u5f9e\u8907\u88fd\u3001\u96d9\u4e3b\u8907\u88fd\u9084\u662f\u7fa4\u96c6\u6280\u8853\uff0c\u9078\u64c7\u5408\u9069\u7684\u540c\u6b65\u65b9\u5f0f\u53ef\u4ee5\u6709\u6548\u63d0\u9ad8\u6578\u64da\u7684\u53ef\u7528\u6027\u548c\u4e00\u81f4\u6027\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u6216 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u4f86\u90e8\u7f72MySQL\u6578\u64da\u5eab\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u9019\u4e9b\u6280\u8853\u5f8c\uff0c\u4f01\u696d\u53ef\u4ee5\u6839\u64da\u81ea\u8eab\u9700\u6c42\u9078\u64c7\u6700\u5408\u9069\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22MySQL\u6578\u64da\u5eab\u7684\u540c\u6b65\u5be6\u4f8b\u6f14\u793a\uff0c\u5b78\u7fd2\u5982\u4f55\u6709\u6548\u5730\u5be6\u73fe\u6578\u64da\u540c\u6b65\uff0c\u63d0\u5347\u6578\u64da\u4e00\u81f4\u6027\u8207\u53ef\u9760\u6027\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-76462","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76462","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=76462"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76462\/revisions"}],"predecessor-version":[{"id":76463,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76462\/revisions\/76463"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}