{"id":76526,"date":"2024-10-16T07:27:15","date_gmt":"2024-10-15T23:27:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/76526\/"},"modified":"2024-10-16T07:27:16","modified_gmt":"2024-10-15T23:27:16","slug":"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e9%9b%86%e7%be%a4%e5%af%a6%e7%8f%be%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e7%9a%84%e5%ae%89%e8%a3%9d%e9%85%8d%e7%bd%ae%e8%a9%b3%e8%a7%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/76526\/","title":{"rendered":"MySQL\u6578\u64da\u5eab\u96c6\u7fa4\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u7684\u5b89\u88dd\u914d\u7f6e\u8a73\u89e3"},"content":{"rendered":"<h1 id=\"mysql%e6%95%b8%e6%93%9a%e5%ba%ab%e9%9b%86%e7%be%a4%e5%af%a6%e7%8f%be%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e7%9a%84%e5%ae%89%e8%a3%9d%e9%85%8d%e7%bd%ae%e8%a9%b3%e8%a7%a3-ErYWCDNdzn\">MySQL\u6578\u64da\u5eab\u96c6\u7fa4\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u7684\u5b89\u88dd\u914d\u7f6e\u8a73\u89e3<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\u5c0d\u65bc\u4f01\u696d\u7684\u6210\u529f\u81f3\u95dc\u91cd\u8981\u3002MySQL\u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u4e2d\u3002\u70ba\u4e86\u63d0\u9ad8MySQL\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\uff0c\u5be6\u73fe\u6578\u64da\u5eab\u96c6\u7fa4\u548c\u8ca0\u8f09\u5747\u8861\u6210\u70ba\u4e86\u4e00\u500b\u91cd\u8981\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u6578\u64da\u5eab\u96c6\u7fa4\u4ee5\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmysql%e6%95%b8%e6%93%9a%e5%ba%ab%e9%9b%86%e7%be%a4%ef%bc%9f-ErYWCDNdzn\">\u4ec0\u9ebc\u662fMySQL\u6578\u64da\u5eab\u96c6\u7fa4\uff1f<\/h2>\n<p>MySQL\u6578\u64da\u5eab\u96c6\u7fa4\u662f\u4e00\u7a2e\u5c07\u591a\u500bMySQL\u5be6\u4f8b\u7d44\u5408\u5728\u4e00\u8d77\u7684\u67b6\u69cb\uff0c\u9019\u4e9b\u5be6\u4f8b\u53ef\u4ee5\u5354\u540c\u5de5\u4f5c\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u7684\u6027\u80fd\u548c\u53ef\u7528\u6027\u3002\u901a\u904e\u5c07\u6578\u64da\u5206\u6563\u5230\u591a\u500b\u4f3a\u670d\u5668\u4e0a\uff0c\u96c6\u7fa4\u53ef\u4ee5\u8655\u7406\u66f4\u591a\u7684\u8acb\u6c42\uff0c\u5f9e\u800c\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u3002\u9019\u7a2e\u67b6\u69cb\u7279\u5225\u9069\u5408\u9700\u8981\u9ad8\u53ef\u7528\u6027\u548c\u9ad8\u6027\u80fd\u7684\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2 id=\"%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1%e7%9a%84%e5%bf%85%e8%a6%81%e6%80%a7-ErYWCDNdzn\">\u8ca0\u8f09\u5747\u8861\u7684\u5fc5\u8981\u6027<\/h2>\n<p>\u96a8\u8457\u7528\u6236\u6578\u91cf\u7684\u589e\u52a0\uff0c\u55ae\u4e00\u6578\u64da\u5eab\u4f3a\u670d\u5668\u53ef\u80fd\u7121\u6cd5\u6eff\u8db3\u6240\u6709\u8acb\u6c42\uff0c\u9019\u6703\u5c0e\u81f4\u6027\u80fd\u4e0b\u964d\u548c\u97ff\u61c9\u6642\u9593\u5ef6\u9577\u3002\u8ca0\u8f09\u5747\u8861\u53ef\u4ee5\u5c07\u8acb\u6c42\u5206\u914d\u5230\u591a\u500b\u4f3a\u670d\u5668\u4e0a\uff0c\u5f9e\u800c\u6e1b\u5c11\u55ae\u4e00\u4f3a\u670d\u5668\u7684\u58d3\u529b\uff0c\u63d0\u9ad8\u6574\u9ad4\u7cfb\u7d71\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9dmysql%e9%9b%86%e7%be%a4%e7%9a%84%e6%ad%a5%e9%a9%9f-ErYWCDNdzn\">\u5b89\u88ddMySQL\u96c6\u7fa4\u7684\u6b65\u9a5f<\/h2>\n<h3 id=\"1-%e7%92%b0%e5%a2%83%e6%ba%96%e5%82%99-ErYWCDNdzn\">1. \u74b0\u5883\u6e96\u5099<\/h3>\n<ul>\n<li>\u78ba\u4fdd\u6240\u6709\u4f3a\u670d\u5668\u4e0a\u5b89\u88dd\u4e86\u76f8\u540c\u7248\u672c\u7684MySQL\u3002<\/li>\n<li>\u914d\u7f6e\u7db2\u7d61\uff0c\u78ba\u4fdd\u6240\u6709\u4f3a\u670d\u5668\u4e4b\u9593\u53ef\u4ee5\u4e92\u76f8\u901a\u4fe1\u3002<\/li>\n<li>\u5b89\u88dd\u5fc5\u8981\u7684\u4f9d\u8cf4\u5305\uff0c\u4f8b\u5982`libaio`\u3002<\/li>\n<\/ul>\n<h3 id=\"2-%e5%ae%89%e8%a3%9dmysql-ErYWCDNdzn\">2. \u5b89\u88ddMySQL<\/h3>\n<pre><code>sudo apt-get update\nsudo apt-get install mysql-server<\/code><\/pre>\n<h3 id=\"3-%e9%85%8d%e7%bd%aemysql%e9%9b%86%e7%be%a4-ErYWCDNdzn\">3. \u914d\u7f6eMySQL\u96c6\u7fa4<\/h3>\n<p>\u5728\u6bcf\u500b\u4f3a\u670d\u5668\u4e0a\uff0c\u7de8\u8f2fMySQL\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4f4d\u65bc`\/etc\/mysql\/my.cnf`\uff09\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>[mysqld]\nserver-id=1\nlog_bin=mysql-bin\nbinlog-do-db=your_database_name\n<\/code><\/pre>\n<p>\u78ba\u4fdd\u6bcf\u500b\u4f3a\u670d\u5668\u7684`server-id`\u662f\u552f\u4e00\u7684\uff0c\u4e26\u6839\u64da\u9700\u8981\u8abf\u6574`log_bin`\u548c`binlog-do-db`\u7684\u8a2d\u7f6e\u3002<\/p>\n<h3 id=\"4-%e5%95%9f%e5%8b%95mysql%e6%9c%8d%e5%8b%99-ErYWCDNdzn\">4. \u555f\u52d5MySQL\u670d\u52d9<\/h3>\n<pre><code>sudo systemctl start mysql<\/code><\/pre>\n<h3 id=\"5-%e9%85%8d%e7%bd%ae%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-ErYWCDNdzn\">5. \u914d\u7f6e\u8ca0\u8f09\u5747\u8861<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528MySQL Proxy\u6216HAProxy\u4f86\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528HAProxy\u7684\u57fa\u672c\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n<pre><code>frontend mysql_front\n    bind *:3306\n    default_backend mysql_back\n\nbackend mysql_back\n    balance roundrobin\n    server mysql1 192.168.1.1:3306 check\n    server mysql2 192.168.1.2:3306 check\n<\/code><\/pre>\n<p>\u9019\u6bb5\u914d\u7f6e\u5c07\u8acb\u6c42\u5747\u52fb\u5730\u5206\u914d\u5230`mysql1`\u548c`mysql2`\u4f3a\u670d\u5668\u4e0a\u3002<\/p>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e9%9b%86%e7%be%a4%e5%92%8c%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-ErYWCDNdzn\">\u6e2c\u8a66\u96c6\u7fa4\u548c\u8ca0\u8f09\u5747\u8861<\/h2>\n<p>\u5728\u914d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528MySQL\u5ba2\u6236\u7aef\u9023\u63a5\u5230HAProxy\u7684IP\u5730\u5740\uff0c\u4e26\u57f7\u884c\u4e00\u4e9b\u67e5\u8a62\u4ee5\u6e2c\u8a66\u96c6\u7fa4\u7684\u6027\u80fd\u548c\u8ca0\u8f09\u5747\u8861\u7684\u6548\u679c\u3002<\/p>\n<pre><code>mysql -h your_haproxy_ip -u your_user -p<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ErYWCDNdzn\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u6211\u5011\u53ef\u4ee5\u6210\u529f\u5730\u5b89\u88dd\u548c\u914d\u7f6eMySQL\u6578\u64da\u5eab\u96c6\u7fa4\u4ee5\u5be6\u73fe\u8ca0\u8f09\u5747\u8861\u3002\u9019\u4e0d\u50c5\u63d0\u9ad8\u4e86\u6578\u64da\u5eab\u7684\u6027\u80fd\uff0c\u9084\u589e\u5f37\u4e86\u7cfb\u7d71\u7684\u53ef\u7528\u6027\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u548c\u7a69\u5b9a\u6027\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\uff0c\u9019\u662f\u4e00\u500b\u975e\u5e38\u6709\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\u4f86\u652f\u6301\u60a8\u7684\u6578\u64da\u5eab\u96c6\u7fa4\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8a0eMySQL\u6578\u64da\u5eab\u96c6\u7fa4\u7684\u5b89\u88dd\u8207\u914d\u7f6e\uff0c\u5be6\u73fe\u9ad8\u6548\u8ca0\u8f09\u5747\u8861\uff0c\u63d0\u5347\u6578\u64da\u8655\u7406\u6027\u80fd\u8207\u7a69\u5b9a\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-76526","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76526","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=76526"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76526\/revisions"}],"predecessor-version":[{"id":76527,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/76526\/revisions\/76527"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=76526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=76526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=76526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}