{"id":183860,"date":"2024-11-10T08:20:20","date_gmt":"2024-11-10T00:20:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/183860\/"},"modified":"2024-11-10T08:20:21","modified_gmt":"2024-11-10T00:20:21","slug":"%e4%bd%bf%e7%94%a8mysql-proxy%e5%91%8a%e7%b5%82%e8%ae%80%e5%af%ab%e9%9b%a2%e5%88%a5%e7%9a%84%e6%93%8d%e4%bd%9c%e5%af%a6%e4%be%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/183860\/","title":{"rendered":"\u4f7f\u7528MySQL Proxy\u544a\u7d42\u8b80\u5beb\u96e2\u5225\u7684\u64cd\u4f5c\u5be6\u4f8b"},"content":{"rendered":"<h1 id=\"%e4%bd%bf%e7%94%a8mysql-proxy%e5%91%8a%e7%b5%82%e8%ae%80%e5%af%ab%e9%9b%a2%e5%88%a5%e7%9a%84%e6%93%8d%e4%bd%9c%e5%af%a6%e4%be%8b-UbYpJFgiCA\">\u4f7f\u7528MySQL Proxy\u544a\u7d42\u8b80\u5beb\u96e2\u5225\u7684\u64cd\u4f5c\u5be6\u4f8b<\/h1>\n<p>\u5728\u73fe\u4ee3\u7684\u6578\u64da\u5eab\u7ba1\u7406\u4e2d\uff0cMySQL Proxy\u662f\u4e00\u500b\u5f37\u5927\u7684\u5de5\u5177\uff0c\u80fd\u5920\u5e6b\u52a9\u7528\u6236\u5728\u8b80\u53d6\u548c\u5beb\u5165\u64cd\u4f5c\u4e4b\u9593\u9032\u884c\u6709\u6548\u7684\u5206\u96e2\u3002\u9019\u7a2e\u5206\u96e2\u4e0d\u50c5\u80fd\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\uff0c\u9084\u80fd\u589e\u5f37\u7cfb\u7d71\u7684\u53ef\u64f4\u5c55\u6027\u548c\u7a69\u5b9a\u6027\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528MySQL Proxy\u4f86\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\uff0c\u4e26\u63d0\u4f9b\u5177\u9ad4\u7684\u64cd\u4f5c\u5be6\u4f8b\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmysql-proxy%ef%bc%9f-UbYpJFgiCA\">\u4ec0\u9ebc\u662fMySQL Proxy\uff1f<\/h2>\n<p>MySQL Proxy\u662f\u4e00\u500b\u4e2d\u4ecb\u5c64\uff0c\u4f4d\u65bc\u5ba2\u6236\u7aef\u548cMySQL\u4f3a\u670d\u5668\u4e4b\u9593\u3002\u5b83\u53ef\u4ee5\u6514\u622a\u548c\u8655\u7406\u5ba2\u6236\u7aef\u7684\u8acb\u6c42\uff0c\u4e26\u6839\u64da\u914d\u7f6e\u5c07\u8acb\u6c42\u8f49\u767c\u5230\u4e0d\u540c\u7684\u4f3a\u670d\u5668\u3002\u9019\u4f7f\u5f97MySQL Proxy\u6210\u70ba\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u7684\u7406\u60f3\u9078\u64c7\uff0c\u56e0\u70ba\u5b83\u53ef\u4ee5\u6839\u64da\u8acb\u6c42\u7684\u985e\u578b\uff08\u8b80\u53d6\u6216\u5beb\u5165\uff09\u5c07\u8acb\u6c42\u8def\u7531\u5230\u76f8\u61c9\u7684\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2%ef%bc%9f-UbYpJFgiCA\">\u70ba\u4ec0\u9ebc\u9700\u8981\u8b80\u5beb\u5206\u96e2\uff1f<\/h2>\n<p>\u5728\u9ad8\u6d41\u91cf\u7684\u61c9\u7528\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u8b80\u53d6\u64cd\u4f5c\u901a\u5e38\u6703\u6bd4\u5beb\u5165\u64cd\u4f5c\u983b\u7e41\u5f97\u591a\u3002\u9019\u610f\u5473\u8457\uff0c\u5982\u679c\u6240\u6709\u7684\u8acb\u6c42\u90fd\u767c\u9001\u5230\u540c\u4e00\u500b\u6578\u64da\u5eab\u4f3a\u670d\u5668\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u6027\u80fd\u74f6\u9838\u3002\u901a\u904e\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\uff0c\u53ef\u4ee5\u5c07\u8b80\u53d6\u8acb\u6c42\u5206\u767c\u5230\u591a\u500b\u5f9e\u4f3a\u670d\u5668\u4e0a\uff0c\u5f9e\u800c\u6e1b\u8f15\u4e3b\u4f3a\u670d\u5668\u7684\u8ca0\u64d4\uff0c\u63d0\u9ad8\u6574\u9ad4\u6027\u80fd\u3002<\/p>\n<h2 id=\"mysql-proxy%e7%9a%84%e5%ae%89%e8%a3%9d%e8%88%87%e9%85%8d%e7%bd%ae-UbYpJFgiCA\">MySQL Proxy\u7684\u5b89\u88dd\u8207\u914d\u7f6e<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5b89\u88ddMySQL Proxy\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u5728Linux\u7cfb\u7d71\u4e0a\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt-get install mysql-proxy<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u914d\u7f6eMySQL Proxy\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u7bc4\u4f8b\uff0c\u60a8\u53ef\u4ee5\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u8abf\u6574\uff1a<\/p>\n<pre><code>[mysql-proxy]\nuser = mysqlproxy\npassword = your_password\nproxy-backend-addresses = master:3306,slave1:3306,slave2:3306\nproxy-read-only = true\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0c\u60a8\u9700\u8981\u5c07`master`\u548c`slave`\u7684\u5730\u5740\u66ff\u63db\u70ba\u5be6\u969b\u7684\u4f3a\u670d\u5668\u5730\u5740\u3002`proxy-read-only`\u8a2d\u7f6e\u70ba`true`\u8868\u793a\u6240\u6709\u7684\u8b80\u53d6\u8acb\u6c42\u5c07\u88ab\u8f49\u767c\u5230\u5f9e\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e6%93%8d%e4%bd%9c%e5%af%a6%e4%be%8b-UbYpJFgiCA\">\u64cd\u4f5c\u5be6\u4f8b<\/h2>\n<p>\u5047\u8a2d\u60a8\u6709\u4e00\u500b\u4e3b\u4f3a\u670d\u5668\u548c\u5169\u500b\u5f9e\u4f3a\u670d\u5668\uff0c\u60a8\u5e0c\u671b\u5c07\u6240\u6709\u7684\u8b80\u53d6\u8acb\u6c42\u767c\u9001\u5230\u5f9e\u4f3a\u670d\u5668\uff0c\u800c\u5beb\u5165\u8acb\u6c42\u5247\u767c\u9001\u5230\u4e3b\u4f3a\u670d\u5668\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u4f7f\u7528MySQL Proxy\u4f86\u5be6\u73fe\u9019\u4e00\u9ede\u7684\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%95%9f%e5%8b%95mysql-proxy-UbYpJFgiCA\">1. \u555f\u52d5MySQL Proxy<\/h3>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5MySQL Proxy\uff1a<\/p>\n<pre><code>mysql-proxy --defaults-file=\/etc\/mysql-proxy.cnf<\/code><\/pre>\n<h3 id=\"2-%e6%b8%ac%e8%a9%a6%e9%80%a3%e6%8e%a5-UbYpJFgiCA\">2. \u6e2c\u8a66\u9023\u63a5<\/h3>\n<p>\u5728\u555f\u52d5MySQL Proxy\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6e2c\u8a66\u9023\u63a5\uff1a<\/p>\n<pre><code>mysql -h 127.0.0.1 -P 4040 -u your_user -p<\/code><\/pre>\n<p>\u9019\u88e1\u7684`4040`\u662fMySQL Proxy\u7684\u9ed8\u8a8d\u7aef\u53e3\u3002\u60a8\u53ef\u4ee5\u6839\u64da\u9700\u8981\u9032\u884c\u66f4\u6539\u3002<\/p>\n<h3 id=\"3-%e5%af%a6%e7%8f%be%e8%ae%80%e5%af%ab%e5%88%86%e9%9b%a2-UbYpJFgiCA\">3. \u5be6\u73fe\u8b80\u5beb\u5206\u96e2<\/h3>\n<p>\u73fe\u5728\uff0c\u60a8\u53ef\u4ee5\u9032\u884c\u8b80\u5beb\u64cd\u4f5c\u3002\u6240\u6709\u7684\u8b80\u53d6\u8acb\u6c42\u5c07\u81ea\u52d5\u8f49\u767c\u5230\u5f9e\u4f3a\u670d\u5668\uff0c\u800c\u5beb\u5165\u8acb\u6c42\u5247\u6703\u767c\u9001\u5230\u4e3b\u4f3a\u670d\u5668\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>-- \u8b80\u53d6\u64cd\u4f5c\nSELECT * FROM your_table;\n\n-- \u5beb\u5165\u64cd\u4f5c\nINSERT INTO your_table (column1, column2) VALUES (value1, value2);\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c`SELECT`\u8a9e\u53e5\u5c07\u88ab\u8f49\u767c\u5230\u5f9e\u4f3a\u670d\u5668\uff0c\u800c`INSERT`\u8a9e\u53e5\u5c07\u88ab\u767c\u9001\u5230\u4e3b\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-UbYpJFgiCA\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528MySQL Proxy\u4f86\u5be6\u73fe\u8b80\u5beb\u5206\u96e2\u662f\u4e00\u7a2e\u6709\u6548\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002\u901a\u904e\u5408\u7406\u7684\u914d\u7f6e\u548c\u64cd\u4f5c\uff0c\u60a8\u53ef\u4ee5\u78ba\u4fdd\u7cfb\u7d71\u5728\u9ad8\u6d41\u91cf\u60c5\u6cc1\u4e0b\u4ecd\u7136\u80fd\u5920\u7a69\u5b9a\u904b\u884c\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u4f86\u7ba1\u7406\u60a8\u7684\u6578\u64da\u5eab\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u90e8\u7f72MySQL Proxy\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u61c9\u7528\u63d0\u4f9b\u66f4\u597d\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u4f7f\u7528MySQL Proxy\u9032\u884c\u8b80\u5beb\u5206\u96e2\u7684\u64cd\u4f5c\u5be6\u4f8b\uff0c\u63d0\u5347\u6578\u64da\u5eab\u6027\u80fd\u8207\u6548\u7387\uff0c\u5be6\u73fe\u9ad8\u6548\u7684\u6578\u64da\u7ba1\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-183860","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183860","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=183860"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183860\/revisions"}],"predecessor-version":[{"id":183861,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/183860\/revisions\/183861"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=183860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=183860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=183860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}