{"id":1339,"date":"2026-04-10T08:46:13","date_gmt":"2026-04-10T00:46:13","guid":{"rendered":"https:\/\/yunyanglib.cn\/?p=1339"},"modified":"2026-04-10T09:05:12","modified_gmt":"2026-04-10T01:05:12","slug":"%e3%80%90mysql%e3%80%91mycat-%e5%ae%9e%e6%88%98%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bb%8e%e5%ae%89%e8%a3%85%e5%88%b0%e9%85%8d%e7%bd%ae%e7%9a%84%e5%ae%8c%e6%95%b4%e6%94%bb%e7%95%a5%ef%bc%88%e9%99%84%e9%81%bf","status":"publish","type":"post","link":"https:\/\/yunyanglib.cn\/?p=1339","title":{"rendered":"\u3010MySQL\u3011MyCAT \u5b9e\u6218\u6307\u5357\uff1a\u4ece\u5b89\u88c5\u5230\u914d\u7f6e\u7684\u5b8c\u6574\u653b\u7565\uff08\u9644\u907f\u5751\u6280\u5de7\uff09"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e91\u626c\uff5e \u6700\u8fd1\u5728\u9879\u76ee\u4e2d\u9700\u8981\u89e3\u51b3 MySQL \u7684\u8bfb\u5199\u5206\u79bb\u548c\u5206\u5e93\u5206\u8868\u95ee\u9898\uff0c\u5bf9\u6bd4\u4e86\u591a\u6b3e\u4e2d\u95f4\u4ef6\u540e\u6700\u7ec8\u9009\u62e9\u4e86 MyCAT\u3002\u8fd9\u7bc7\u535a\u5ba2\u5c31\u6765\u8be6\u7ec6\u8bb0\u5f55\u6211\u7684\u5b9e\u6218\u8fc7\u7a0b\uff0c\u4ece\u6838\u5fc3\u4f5c\u7528\u3001\u67b6\u6784\u539f\u7406\u5230\u4e00\u6b65\u6b65\u5b89\u88c5\u914d\u7f6e\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u6b63\u5728\u8e29\u5751\u7684\u5c0f\u4f19\u4f34\uff5e<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u4e3a\u4ec0\u4e48\u9009\u62e9 MyCAT\uff1f\u6838\u5fc3\u4f5c\u7528\u62c6\u89e3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u505a\u540e\u7aef\u5f00\u53d1\u7684\u540c\u5b66\u90fd\u77e5\u9053\uff0c\u5f53\u6570\u636e\u5e93\u6570\u636e\u91cf\u8fbe\u5230\u4e00\u5b9a\u89c4\u6a21\uff0c\u5355\u5e93\u5355\u8868\u7684\u6027\u80fd\u74f6\u9888\u4f1a\u8d8a\u6765\u8d8a\u660e\u663e\u3002MyCAT \u4f5c\u4e3a\u5f00\u6e90\u7684\u6570\u636e\u5e93\u4e2d\u95f4\u4ef6\uff0c\u5b8c\u7f8e\u89e3\u51b3\u4e86\u8fd9\u4e09\u4e2a\u6838\u5fc3\u95ee\u9898\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8bfb\u5199\u5206\u79bb<\/strong>\uff1a\u5199\u64cd\u4f5c\u8d70\u4e3b\u5e93\uff0c\u8bfb\u8bf7\u6c42\u5206\u6563\u5230\u591a\u4e2a\u4ece\u5e93\uff0c\u76f4\u63a5\u51cf\u8f7b\u4e3b\u5e93\u538b\u529b\uff08\u5b9e\u6d4b\u8bfb\u6027\u80fd\u63d0\u5347 30%+\uff09<\/li>\n\n\n\n<li><strong>\u5206\u5e93\u5206\u8868<\/strong>\uff1a\u5e94\u7528\u5c42\u53ea\u9700\u8fde\u63a5 MyCAT \u7684\u903b\u8f91\u5e93\uff0c\u65e0\u9700\u5173\u5fc3\u5e95\u5c42\u7269\u7406\u5e93\u7684\u62c6\u5206\uff0cMyCAT \u4f1a\u81ea\u52a8\u8def\u7531\u5e76\u5408\u5e76\u7ed3\u679c<\/li>\n\n\n\n<li><strong>\u6545\u969c\u5207\u6362<\/strong>\uff1a\u4e3b\u5e93\u5b95\u673a\u540e\u53ef\u81ea\u52a8\u5207\u6362\u5230\u4ece\u5e93\uff0c\u65e0\u9700\u4eba\u5de5\u5e72\u9884\uff0c\u5927\u5927\u63d0\u5347\u7cfb\u7edf\u53ef\u7528\u6027<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001MyCAT \u6838\u5fc3\u67b6\u6784\u89e3\u6790<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u521a\u5f00\u59cb\u63a5\u89e6\u65f6\u6709\u70b9\u61f5\uff0c\u7406\u6e05\u903b\u8f91\u540e\u5176\u5b9e\u5f88\u7b80\u5355\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"561\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-1024x561.png\" alt=\"\" class=\"wp-image-1360\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-1024x561.png 1024w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-300x164.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-768x420.png 768w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-1536x841.png 1536w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/MyCAT-\u6838\u5fc3\u67b6\u6784-2048x1121.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5ba2\u6237\u7aef\u8fde\u63a5\u7684\u662f MyCAT \u7684\u300c\u903b\u8f91\u5e93\u300d\uff08\u6bd4\u5982\u6211\u914d\u7f6e\u7684<code>mycat<\/code>\u5e93\uff09\uff0c\u80cc\u540e\u6620\u5c04 N \u4e2a MySQL\u300c\u7269\u7406\u5e93\u300d\uff08\u5982 db01\u3001db02\uff09<\/li>\n\n\n\n<li>\u6211\u4eec\u64cd\u4f5c\u7684\u300c\u903b\u8f91\u8868\u300d\uff08table\uff09\uff0c\u5b9e\u9645\u5bf9\u5e94\u591a\u4e2a\u7269\u7406\u8868\uff08\u5982 table01\u3001table02\uff09<\/li>\n\n\n\n<li>\u5de5\u4f5c\u6d41\u7a0b\uff1a\u5ba2\u6237\u7aef SQL \u2192 MyCAT \u89e3\u6790\uff08\u5224\u65ad\u8bfb\u5199 \/ \u5206\u7247\uff09\u2192 \u8def\u7531\u5230\u5bf9\u5e94\u7269\u7406\u5e93 \u2192 \u7ed3\u679c\u5408\u5e76 \u2192 \u8fd4\u56de\u5ba2\u6237\u7aef<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u8bf4\uff0cMyCAT \u5c31\u662f\u4e00\u4e2a &#8220;\u4e2d\u95f4\u4ee3\u7406&#8221;\uff0c\u8ba9\u5e94\u7528\u5c42\u65e0\u9700\u5173\u5fc3\u5e95\u5c42\u6570\u636e\u5e93\u7684\u590d\u6742\u67b6\u6784\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u5b9e\u6218\u90e8\u7f72\uff1a3 \u53f0\u670d\u52a1\u5668\u73af\u5883\u914d\u7f6e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u8bf4\u660e\u6211\u7684\u73af\u5883\uff1a3 \u53f0 MySQL \u5b9e\u4f8b\uff08151 \u4e3a\u4e3b\u5e93\u3001152 \u4e3a\u4ece\u5e93\u3001153 \u5355\u72ec\u90e8\u7f72 MyCAT\uff09\uff0c\u64cd\u4f5c\u7cfb\u7edf\u5747\u4e3a CentOS 7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u524d\u7f6e\u4f9d\u8d56\uff1a\u5b89\u88c5 JDK<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">MyCAT \u57fa\u4e8e Java \u5f00\u53d1\uff0c\u5fc5\u987b\u5148\u88c5 JDK 1.8\uff08\u6ce8\u610f\uff1a\u9ad8\u7248\u672c\u53ef\u80fd\u4e0d\u517c\u5bb9\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u4e00\u952e\u5b89\u88c5JDK 1.8\nyum install java-1.8.0-openjdk java-1.8.0-openjdk-devel -y\n# \u9a8c\u8bc1\u5b89\u88c5\u6210\u529f\uff08\u51fa\u73b0\u7248\u672c\u53f7\u5373\u53ef\uff09\njava -version\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u4e0b\u8f7d\u5e76\u89e3\u538b MyCAT<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><br>MyCAT 2.x\u7248\u672c\u9700\u4e0b\u8f7d\u201c\u5b89\u88c5\u6a21\u677f\u201d\u548c\u201c\u6838\u5fc3JAR\u5305\u201d\uff0c\u64cd\u4f5c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8fdb\u5165\u6e90\u7801\u76ee\u5f55\ncd \/usr\/src\n# \u4e0b\u8f7d\u5b89\u88c5\u5305\uff08\u5efa\u8bae\u4fdd\u5b58\u94fe\u63a5\uff0c\u907f\u514d\u5931\u6548\uff09\nwget http:\/\/dl.mycat.org.cn\/2.0\/install-template\/mycat2-install-template-1.21.zip\n# \u89e3\u538b\uff08\u9700\u63d0\u524d\u88c5unzip\uff1ayum install unzip -y\uff09\nunzip mycat2-install-template-1.21.zip\n\n# \u4e0b\u8f7d\u6838\u5fc3jar\u5305\uff08\u5173\u952e\u6b65\u9aa4\uff0c\u4e0d\u80fd\u6f0f\uff01\uff09\ncd mycat\/lib\/\nwget http:\/\/dl.mycat.org.cn\/2.0\/1.21-release\/mycat2-1.21-release-jar-with-dependencies.jar\n\n# \u79fb\u52a8\u5230\u5e38\u7528\u76ee\u5f55\nmv \/usr\/src\/mycat \/usr\/local\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u914d\u7f6e MySQL \u6388\u6743<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e3b\u5e93\uff08192.168.184.151\uff09\u521b\u5efa MyCAT \u4e13\u7528\u8fde\u63a5\u7528\u6237\uff0c\u6388\u4e88\u6240\u6709\u6743\u9650\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- 1. \u521b\u5efaMyCAT\u8fde\u63a5\u7528\u6237\uff08\u5141\u8bb8\u6240\u6709IP\u8bbf\u95ee\uff0c\u5bc6\u7801Ud9_a8Gca1\uff09\nCREATE USER 'mycat_rw'@'%' IDENTIFIED WITH MYSQL_NATIVE_PASSWORD BY 'Ud9_a8Gca1';\n\n-- 2. \u6388\u4e88\u8be5\u7528\u6237\u6240\u6709\u5e93\u8868\u7684\u6743\u9650\uff08\u751f\u4ea7\u73af\u5883\u53ef\u6309\u9700\u7f29\u5c0f\u6743\u9650\u8303\u56f4\uff09\nGRANT ALL ON *.* TO 'mycat_rw'@'%';\n\n-- 3. \u521b\u5efaMyCAT\u8fde\u63a5\u7684\u903b\u8f91\u5e93\uff08\u540e\u7eedMyCAT\u914d\u7f6e\u5c06\u6307\u5411\u8be5\u5e93\uff09\nCREATE DATABASE mycat;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\u4fee\u6539<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u90e8\u5206\u662f\u91cd\u70b9\uff0c\u6211\u6574\u7406\u4e86\u5173\u952e\u914d\u7f6e\u6587\u4ef6\u7684\u4fee\u6539\u8981\u70b9\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\uff081\uff09\u6570\u636e\u6e90\u914d\u7f6e\uff08\u8fde\u63a5 MySQL \u4e3b\u5e93\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/usr\/local\/mycat\/\nvim conf\/datasources\/prototypeDs.datasource.json\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u4ee5\u4e0b\u6838\u5fc3\u53c2\u6570\uff08\u5176\u4ed6\u9ed8\u8ba4\u5373\u53ef\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"password\": \"Ud9_a8Gca1\", \/\/ \u4e3b\u5e93mycat_rw\u7528\u6237\u5bc6\u7801\n  \"type\": \"JDBC\",\n  \"url\": \"jdbc:mysql:\/\/192.168.184.151:3306\/mycat?useUnicode=true&amp;serverTimezone=Asia\/Shanghai&amp;characterEncoding=UTF-8\",\n  \"user\": \"mycat_rw\",\n  \"instanceType\": \"READ_WRITE\" \/\/ \u8bfb\u5199\u6a21\u5f0f\uff08\u4ece\u5e93\u8bbe\u4e3aREAD\uff09\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\uff082\uff09MyCAT \u767b\u5f55\u7528\u6237\u914d\u7f6e<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>vim conf\/users\/root.user.json\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4fee\u6539\u767b\u5f55\u8d26\u53f7\u5bc6\u7801\uff08\u5e94\u7528\u5c42\u8fde\u63a5 MyCAT \u65f6\u4f7f\u7528\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"dialect\": \"mysql\",\n  \"ip\": null, \/\/ \u5efa\u8bae\u8bbe\u4e3anull\uff0c\u5141\u8bb8\u6240\u6709IP\u8bbf\u95ee\uff08\u751f\u4ea7\u73af\u5883\u53ef\u6307\u5b9aIP\uff09\n  \"password\": \"UdYca86a\", \/\/ MyCAT\u767b\u5f55\u5bc6\u7801\n  \"transactionType\": \"proxy\", \/\/ \u4e8b\u52a1\u7c7b\u578b\uff08proxy=\u672c\u5730\u4e8b\u52a1\uff0cXA=\u5206\u5e03\u5f0f\u4e8b\u52a1\uff09\n  \"username\": \"mycat\" \/\/ MyCAT\u767b\u5f55\u7528\u6237\u540d\n}<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a\u82e5\u9700\u521b\u5efa\u591a\u4e2aMyCAT\u8bbf\u95ee\u7528\u6237\uff0c\u53ef\u590d\u5236\u8be5\u6587\u4ef6\u5e76\u547d\u540d\u4e3a\u201c\u7528\u6237\u540d.user.json\u201d\uff08\u5982<code>test.user.json<\/code>\uff09\u3002<\/p>\n<\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">\uff083\uff09\u96c6\u7fa4\u914d\u7f6e\uff08\u4e3b\u4ece\u6a21\u5f0f\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>vim conf\/clusters\/prototype.cluster.json\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u952e\u914d\u7f6e\u8bf4\u660e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"clusterType\": \"MASTER_SLAVE\", \/\/ \u4e3b\u4ece\u96c6\u7fa4\u6a21\u5f0f\n  \"heartbeat\": \"show status like 'wsrep%'\", \/\/ \u5fc3\u8df3\u68c0\u6d4bSQL\n  \"masters\": &#91;\"prototypeDs\"], \/\/ \u4e3b\u6570\u636e\u6e90\uff08\u5bf9\u5e94\u4e0a\u9762\u7684\u914d\u7f6e\uff09\n  \"name\": \"prototype\",\n  \"readBalanceType\": \"BALANCE_ALL_READ\", \/\/ \u8bfb\u8d1f\u8f7d\u5747\u8861\uff08\u6240\u6709\u4ece\u5e93\u53c2\u4e0e\uff09\n  \"switchType\": \"SWITCH\" \/\/ \u5141\u8bb8\u4e3b\u4ece\u5207\u6362\n}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u542f\u52a8 MyCAT \u5e76\u9a8c\u8bc1<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code># \u8d4b\u4e88\u6267\u884c\u6743\u9650\nchmod +x .\/bin\/*\n\n# \u542f\u52a8\uff08\u9996\u6b21\u542f\u52a8\u53ef\u80fd\u8f83\u6162\uff0c\u8010\u5fc3\u7b49\u5f85\uff09\n.\/bin\/mycat start\n\n# \u67e5\u770b\u72b6\u6001\uff08\u51fa\u73b0\"MyCAT Server is running\"\u5373\u4e3a\u6210\u529f\uff09\n.\/bin\/mycat status\n\n# \u67e5\u770b\u65e5\u5fd7\uff08\u542f\u52a8\u5931\u8d25\u65f6\u6392\u67e5\u7528\uff09\ntail -f \/usr\/local\/mycat\/logs\/wrapper.log\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u767b\u5f55 MyCAT \u6d4b\u8bd5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><br>MyCAT\u9ed8\u8ba4\u6570\u636e\u8bbf\u95ee\u7aef\u53e3\u4e3a<code>8066<\/code>\uff0c<code>192.168.184.153<\/code>\u4e0a\u4f7f\u7528MySQL\u5ba2\u6237\u7aef\u5de5\u5177\u767b\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u7528MySQL\u5ba2\u6237\u7aef\u8fde\u63a5\uff08\u7aef\u53e38066\u662fMyCAT\u9ed8\u8ba4\u6570\u636e\u7aef\u53e3\uff09\nmysql -umycat -p'UdYca86a' -P8066 -h192.168.184.153\n\n# \u8fde\u63a5\u6210\u529f\u540e\uff0c\u6267\u884cSQL\u9a8c\u8bc1\nshow databases; <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"760\" height=\"568\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-23.png\" alt=\"\" class=\"wp-image-1354\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-23.png 760w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-23-300x224.png 300w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"NVMEf\">\u56db\u3001MyCAT\u5173\u952e\u914d\u7f6e\u6587\u4ef6\u8be6\u89e3<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u5f83e1fe\">MyCAT\u7684\u6838\u5fc3\u80fd\u529b\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u5b9e\u73b0\uff0c\u4ee5\u4e0b\u662f\u5e38\u7528\u914d\u7f6e\u6587\u4ef6\u7684\u529f\u80fd\u4e0e\u5173\u952e\u53c2\u6570\u8bf4\u660e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"jIyZE\">1. \u670d\u52a1\u914d\u7f6e\uff1aserver.json<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u78ee740c\">\u8def\u5f84\uff1a<code>\/usr\/local\/mycat\/conf\/server.json<\/code><br>\u4f5c\u7528\uff1a\u5b9a\u4e49MyCAT\u7684\u670d\u52a1\u7aef\u53e3\u3001\u7ebf\u7a0b\u6c60\u3001\u65e5\u5fd7\u7b49\u5168\u5c40\u914d\u7f6e\uff0c\u65e0\u9700\u9891\u7e41\u4fee\u6539\uff0c\u9ed8\u8ba4\u5373\u53ef\u6ee1\u8db3\u57fa\u7840\u9700\u6c42\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"924\" height=\"792\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-19.png\" alt=\"\" class=\"wp-image-1350\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-19.png 924w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-19-300x257.png 300w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-19-768x658.png 768w\" sizes=\"(max-width: 924px) 100vw, 924px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"NNoZB\">2. \u7528\u6237\u914d\u7f6e\uff1axxx.user.json<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u82685daa\">\u8def\u5f84\uff1a<code>\/usr\/local\/mycat\/conf\/users\/<\/code><br>\u547d\u540d\u89c4\u5219\uff1a<code>\u7528\u6237\u540d.user.json<\/code>\uff08\u5982<code>mycat.user.json<\/code>\uff09<br>\u5173\u952e\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>transactionType<\/code>\uff1a\u4e8b\u52a1\u7c7b\u578b\uff0c<code>proxy<\/code>\uff08\u672c\u5730\u4e8b\u52a1\uff0c\u9002\u7528\u4e8e\u5355\u5e93\u64cd\u4f5c\uff09\u3001<code>XA<\/code>\uff08\u5206\u5e03\u5f0f\u4e8b\u52a1\uff0c\u9002\u7528\u4e8e\u8de8\u5e93\u64cd\u4f5c\uff0c\u9700\u540e\u7aefMySQL\u652f\u6301\uff09\uff1b<\/li>\n\n\n\n<li>\u53ef\u901a\u8fc7SQL\u52a8\u6001\u67e5\u8be2\/\u4fee\u6539\u4e8b\u52a1\u7c7b\u578b\uff1a<\/li>\n<\/ul>\n\n\n\n<pre id=\"ZJH3V\" class=\"wp-block-code\"><code>-- \u67e5\u8be2\u5f53\u524d\u4e8b\u52a1\u7c7b\u578b\nSELECT @@transaction_policy;\n\n-- \u4fee\u6539\u4e3a\u5206\u5e03\u5f0f\u4e8b\u52a1\uff08XA\uff09\nSET transaction_policy = 'xa';<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"764\" height=\"187\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-20.png\" alt=\"\" class=\"wp-image-1351\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-20.png 764w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-20-300x73.png 300w\" sizes=\"(max-width: 764px) 100vw, 764px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"u6wKA\">3. \u6570\u636e\u6e90\u914d\u7f6e\uff1axxx.datasource.json<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"uf06b07fa\">\u8def\u5f84\uff1a<code>\/usr\/local\/mycat\/conf\/datasources\/<\/code><br>\u547d\u540d\u89c4\u5219\uff1a<code>\u6570\u636e\u6e90\u540d.datasource.json<\/code>\uff08\u5982<code>prototypeDs.datasource.json<\/code>\uff09<br>\u5173\u952e\u53c2\u6570\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u53c2\u6570<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td><code>dbType<\/code><\/td><td>\u6570\u636e\u5e93\u7c7b\u578b\uff08\u5982mysql\uff09<\/td><\/tr><tr><td><code>idleTimeout<\/code><\/td><td>\u7a7a\u95f2\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff08\u6beb\u79d2\uff09<\/td><\/tr><tr><td><code>instanceType<\/code><\/td><td>\u5b9e\u4f8b\u7c7b\u578b\uff08READ_WRITE=\u8bfb\u5199\uff0cREAD=\u53ea\u8bfb\uff0cWRITE=\u53ea\u5199\uff09<\/td><\/tr><tr><td><code>maxCon<\/code><\/td><td>\u6700\u5927\u8fde\u63a5\u6570\uff08\u907f\u514d\u8fde\u63a5\u8fc7\u591a\u5bfc\u81f4\u6570\u636e\u5e93\u538b\u529b\uff09<\/td><\/tr><tr><td><code>minCon<\/code><\/td><td>\u6700\u5c0f\u7a7a\u95f2\u8fde\u63a5\u6570\uff08\u4fdd\u8bc1\u5feb\u901f\u54cd\u5e94\uff09<\/td><\/tr><tr><td><code>url<\/code><\/td><td>JDBC\u8fde\u63a5\u5730\u5740\uff08IP+\u7aef\u53e3+\u5e93\u540d+\u53c2\u6570\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/i-blog.csdnimg.cn\/direct\/093a4d030edb439a988de9c1a01e8c5c.png\" alt=\"\" title=\"null\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"eATqm\">4. \u903b\u8f91\u5e93\u8868\u914d\u7f6e\uff1amysql.schema.json<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u32bf88a7\">\u8def\u5f84\uff1a<code>\/usr\/local\/mycat\/conf\/schemas\/mysql.schema.json<\/code><br>\u4f5c\u7528\uff1a\u5173\u8054\u903b\u8f91\u5e93\u4e0e\u540e\u7aef\u6570\u636e\u6e90\/\u96c6\u7fa4\uff0c\u5173\u952e\u53c2\u6570\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>schemaName<\/code>\uff1a\u5ba2\u6237\u7aef\u8fde\u63a5MyCAT\u65f6\u4f7f\u7528\u7684\u903b\u8f91\u5e93\u540d\uff08\u5982<code>mycat<\/code>\uff09\uff1b<\/li>\n\n\n\n<li><code>targetName<\/code>\uff1a\u5173\u8054\u7684\u6570\u636e\u6e90\u6216\u96c6\u7fa4\u540d\uff08\u5982<code>prototype<\/code>\uff0c\u5bf9\u5e94\u96c6\u7fa4\u914d\u7f6e\u6587\u4ef6\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"411\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-21.png\" alt=\"\" class=\"wp-image-1352\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-21.png 762w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-21-300x162.png 300w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"UTVS7\">5. \u96c6\u7fa4\u914d\u7f6e\uff1axxx.cluster.json<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"u32109661\">\u8def\u5f84\uff1a<code>\/usr\/local\/mycat\/conf\/clusters\/prototype.cluster.json<\/code><br>\u4f5c\u7528\uff1a\u914d\u7f6e\u4e3b\u4ece\u96c6\u7fa4\u3001\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\u3001\u6545\u969c\u5207\u6362\u89c4\u5219\uff0c\u5173\u952e\u53c2\u6570\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u53c2\u6570<\/td><td>\u8bf4\u660e<\/td><\/tr><tr><td><code>clusterType<\/code><\/td><td>\u96c6\u7fa4\u7c7b\u578b\uff08MASTER_SLAVE=\u4e3b\u4ece\uff0cSINGLE_NODE=\u5355\u8282\u70b9\uff0cGENERAL_CLUSTER=PXC\u96c6\u7fa4\uff09<\/td><\/tr><tr><td><code>readBalanceType<\/code><\/td><td>\u8bfb\u8d1f\u8f7d\u5747\u8861\u7b56\u7565\uff08BALANCE_ALL=\u6240\u6709\u8282\u70b9\uff0cBALANCE_ALL_READ=\u53ea\u8bfb\u8282\u70b9\uff0cBALANCE_READ_WRITE=\u8bfb\u5199\u8282\u70b9\u4f18\u5148\u8bfb\uff09<\/td><\/tr><tr><td><code>switchType<\/code><\/td><td>\u6545\u969c\u5207\u6362\u7c7b\u578b\uff08SWITCH=\u81ea\u52a8\u5207\u6362\uff0cNOT_SWITCH=\u4e0d\u5207\u6362\uff09<\/td><\/tr><tr><td><code>heartbeat<\/code><\/td><td>\u5fc3\u8df3\u68c0\u6d4bSQL\uff08\u9ed8\u8ba4<code>select 1<\/code>\uff0c\u7528\u4e8e\u68c0\u6d4b\u8282\u70b9\u5b58\u6d3b\uff09<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"761\" height=\"362\" src=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-22.png\" alt=\"\" class=\"wp-image-1353\" srcset=\"https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-22.png 761w, https:\/\/yunyanglib.cn\/wp-content\/uploads\/2026\/04\/image-22-300x143.png 300w\" sizes=\"(max-width: 761px) 100vw, 761px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u5e38\u7528\u64cd\u4f5c\u4e0e\u907f\u5751\u603b\u7ed3<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5e38\u7528\u547d\u4ee4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/bin\/mycat stop # \u505c\u6b62\n.\/bin\/mycat restart # \u91cd\u542f\n.\/bin\/mycat status # \u67e5\u770b\u72b6\u6001\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u8e29\u5751\u8bb0\u5f55<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5fd8\u8bb0\u5237\u65b0 MySQL \u6743\u9650\uff1a\u5bfc\u81f4 MyCAT \u8fde\u63a5\u4e3b\u5e93\u5931\u8d25\uff0c\u6267\u884c<code>FLUSH PRIVILEGES<\/code>\u5373\u53ef<\/li>\n\n\n\n<li>JDK \u7248\u672c\u4e0d\u517c\u5bb9\uff1a\u9ad8\u7248\u672c JDK \u4f1a\u5bfc\u81f4 MyCAT \u542f\u52a8\u62a5\u9519\uff0c\u52a1\u5fc5\u7528 1.8 \u7248\u672c<\/li>\n\n\n\n<li>\u6570\u636e\u6e90 URL \u9519\u8bef\uff1a\u6f0f\u5199\u7f16\u7801\u6216\u65f6\u533a\u53c2\u6570\uff0c\u5bfc\u81f4\u4e2d\u6587\u4e71\u7801\u6216\u8fde\u63a5\u8d85\u65f6<\/li>\n\n\n\n<li>\u96c6\u7fa4\u914d\u7f6e\u9519\u8bef\uff1amasters \u53c2\u6570\u672a\u5bf9\u5e94\u6570\u636e\u6e90\u540d\u79f0\uff0c\u5bfc\u81f4\u4e3b\u4ece\u5207\u6362\u5931\u8d25<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u914d\u7f6e\u591a\u4e2a\u4ece\u5e93\uff0c\u63d0\u5347\u8bfb\u6027\u80fd<\/li>\n\n\n\n<li>\u5206\u5e03\u5f0f\u4e8b\u52a1\u9700\u786e\u4fdd\u540e\u7aef MySQL \u652f\u6301 XA \u534f\u8bae<\/li>\n\n\n\n<li>\u5b9a\u671f\u5907\u4efd\u914d\u7f6e\u6587\u4ef6\uff0c\u907f\u514d\u4fee\u6539\u9519\u8bef\u65e0\u6cd5\u56de\u6eda<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5927\u5bb6\u597d\uff0c\u6211\u662f\u4e91\u626c\uff5e \u6700\u8fd1\u5728\u9879\u76ee\u4e2d\u9700\u8981\u89e3\u51b3 MySQL \u7684\u8bfb\u5199\u5206\u79bb\u548c\u5206\u5e93\u5206\u8868\u95ee\u9898\uff0c\u5bf9\u6bd4\u4e86\u591a\u6b3e\u4e2d\u95f4\u4ef6\u540e\u6700\u7ec8\u9009\u62e9\u4e86 <\/p>\n<div class=\"more-link\">\n\t\t\t\t <a href=\"https:\/\/yunyanglib.cn\/?p=1339\" class=\"link-btn theme-btn\"><span>Read More <\/span> <i class=\"fa fa-caret-right\"><\/i><\/a>\n\t\t\t<\/div>\n","protected":false},"author":1,"featured_media":1355,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[16],"class_list":["post-1339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-mysql"],"_links":{"self":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1339"}],"version-history":[{"count":4,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1339\/revisions"}],"predecessor-version":[{"id":1361,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/posts\/1339\/revisions\/1361"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=\/wp\/v2\/media\/1355"}],"wp:attachment":[{"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yunyanglib.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}