﻿{"id":401,"date":"2017-08-04T20:22:45","date_gmt":"2017-08-04T12:22:45","guid":{"rendered":"http:\/\/www.chenweikang.top\/?p=401"},"modified":"2017-09-19T11:36:30","modified_gmt":"2017-09-19T03:36:30","slug":"mycat%e5%ae%9e%e9%aa%8c%ef%bc%883%ef%bc%89-%e7%ae%80%e5%8d%95%e9%85%8d%e7%bd%aemycat%ef%bc%8c%e5%ae%9e%e7%8e%b0%e8%af%bb%e5%86%99%e5%88%86%e7%a6%bb","status":"publish","type":"post","link":"https:\/\/www.chenweikang.top\/?p=401","title":{"rendered":"Mycat\u4e3b\u4ece\u540c\u6b65\u3001\u8bfb\u5199\u5206\u79bb\u3001\u5206\u5e93\u5206\u8868\uff083\uff09- \u7b80\u5355\u914d\u7f6eMycat\uff0c\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb"},"content":{"rendered":"<blockquote><p>MyCat\u662f\u57fa\u4e8e\u963f\u91cc\u5df4\u5df4\u7684\u5f00\u6e90\u4ea7\u54c1CoBar\u6f14\u53d8\u800c\u6765\uff0c\u4ee5\u4ee3\u66ff\u6602\u8d35\u7684oracle\u7684MySQL\u96c6\u7fa4\u7684\u4e2d\u95f4\u4ef6\u3002\u5173\u4e8eMyCat\u7684\u4ecb\u7ecd\u5728\u6b64\u4e0d\u591a\u8d58\u8ff0\uff08\u8be6\u7ec6\u4ecb\u7ecd \uff1a <a href=\"http:\/\/www.cnblogs.com\/MRRAOBX\/articles\/5045416.html\" target=\"_blank\" rel=\"noopener\">\u67e5\u770bMycat\u7684\u8be6\u7ec6\u4ecb\u7ecd<\/a>\uff09\u3002<\/p><\/blockquote>\n<h3><strong>\u57fa\u4e8e\u4e0a\u7bc7\u7684\u5b9e\u9a8c\uff0c\u6211\u4eec\u5f53\u524d\u7684\u73af\u5883\u4e3a\uff1a<\/strong><\/h3>\n<p><span style=\"color: #993300;\">\u89d2\u8272 \u00a0 \u00a0 \u00a0\u670d\u52a1\u7aef\u53e3 \u00a0 \u00a0 \u00a0\u7528\u6237 \u00a0 \u00a0 \u00a0 \u00a0\u5bc6\u7801<\/span><\/p>\n<p><span style=\"color: #008000;\">master \u00a03306 \u00a0 \u00a0 \u00a0 root \u00a0 \u00a0root@3306<\/span><\/p>\n<p><span style=\"color: #008000;\">slave \u00a0 \u00a0 3307 \u00a0 \u00a0 \u00a0 root \u00a0 \u00a0root@3307<\/span><\/p>\n<p><span style=\"color: #008000;\">slave \u00a0 \u00a0 3308 \u00a0 \u00a0 \u00a0 root \u00a0 \u00a0root@3308<\/span><\/p>\n<p><span style=\"color: #800000;\">\u5df2\u7ecf\u5b9e\u73b0master\u4e2d\u53d1\u751f\u5199\u64cd\u4f5c\u4f1a\u81ea\u52a8\u540c\u6b65\u5230\u4e24\u4e2aslave\u670d\u52a1\uff0c\u4e0b\u9762\u5c06\u5728\u6b64\u73af\u5883\u4e0b\u914d\u7f6emycat\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb\uff0c\u5c063306\u4f5c\u4e3a\u5199\u5e93\uff0c3307\u30013308\u4f5c\u4e3a\u8bfb\u64cd\u4f5c\u7528\u7684\u5e93\u3002<\/span><\/p>\n<h2>\u4e00\u3001\u4e0b\u8f7d\u3001\u914d\u7f6eMyCat<\/h2>\n<h3>1.\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5df2\u7f16\u8bd1\u597d\u7684\u5b89\u88c5\u5305<\/h3>\n<pre class=\"prettyprint linenums\">cd \/software\/\r\nwget http:\/\/dl.mycat.io\/1.6-RELEASE\/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz\r\ntar -zxvf  Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz\r\n<\/pre>\n<h3>2.\u914d\u7f6ejava\u73af\u5883<\/h3>\n<p>mycat\u57fa\u4e8ejdk1.7\uff0c\u6700\u4f4e\u8981\u7528jdk1.7\u7684\u7248\u672c\uff0c\u5f53\u524d\u6d4b\u8bd5\u7528\u7684jdk1.8<\/p>\n<pre class=\"prettyprint linenums\">[root@iZ2ze1np3s3kfsddhxqr0gZ software]# java -version \r\njava version \"1.8.0_141\"\r\nJava(TM) SE Runtime Environment (build 1.8.0_141-b15)\r\nJava HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)\r\n<\/pre>\n<p>\u7701\u7565\u914d\u7f6e\u8fc7\u7a0b...<\/p>\n<h3>3.\u914d\u7f6emycat<\/h3>\n<p>mycat\u914d\u7f6e\u6587\u4ef6\u4e0b\u90fd\u5728conf\u76ee\u5f55\u4e0b\uff0c\u672c\u6d4b\u8bd5\u9700\u8981\u914d\u7f6e\u4e24\u4e2a\u6587\u4ef6<\/p>\n<p><span style=\"color: #800000;\">server.xml \u00a0\uff1a\u00a0\u4fdd\u5b58\u4e86\u6240\u6709mycat\u9700\u8981\u7684\u7cfb\u7edf\u914d\u7f6e\u4fe1\u606f\u3002\u5176\u5728\u4ee3\u7801\u5185\u76f4\u63a5\u7684\u6620\u5c04\u7c7b\u4e3aSystemConfig\u7c7b\u3002\u73b0\u5728\u5c31\u5bf9\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u3002<\/span><\/p>\n<p><span style=\"color: #800000;\">Schema.xml \uff1a\u4f5c\u4e3aMyCat\u4e2d\u91cd\u8981\u7684\u914d\u7f6e\u6587\u4ef6\u4e4b\u4e00\uff0c\u7ba1\u7406\u7740MyCat\u7684\u903b\u8f91\u5e93\u3001\u8868\u3001\u5206\u7247\u89c4\u5219\u3001DataNode\u4ee5\u53caDataSource\u7b49\u3002<\/span><\/p>\n<p><strong>\u914d\u7f6eserver.xml:<\/strong><\/p>\n<blockquote><p>&lt;user name=\"root\"&gt;<br \/>\n&lt;property name=\"password\"&gt;123456&lt;\/property&gt;<br \/>\n&lt;property name=\"schemas\"&gt;<span style=\"color: #ff0000;\">test_db<\/span>&lt;\/property&gt;<\/p>\n<p>&lt;\/user&gt;<\/p>\n<p>&lt;user name=\"user\"&gt;<br \/>\n&lt;property name=\"password\"&gt;user&lt;\/property&gt;<br \/>\n&lt;property name=\"schemas\"&gt;<span style=\"color: #ff0000;\">test_db<\/span>&lt;\/property&gt;<br \/>\n&lt;property name=\"readOnly\"&gt;true&lt;\/property&gt;<br \/>\n&lt;\/user&gt;<\/p><\/blockquote>\n<p>\u914d\u7f6e\u4e24\u4e2a\u7528\u6237 \uff0croot \u548cuser (\u53ea\u8bfb\u6743\u9650)\uff0c\u8fd9\u91cc\u7684\u7528\u6237\u4e0e\u6570\u636e\u5e93\u65e0\u5173\uff0c\u4f5c\u4e3amycat\u767b\u5f55\u65f6\u7528\uff0ctest_db\u4e3a\u903b\u8f91\u6570\u636e\u5e93\uff0c\u4e0eschema.xml\u4e2d\u5bf9\u5e94<\/p>\n<p><strong>\u914d\u7f6eschema.xml:<\/strong><\/p>\n<blockquote><p>&lt;?xml version=\"1.0\"?&gt;<br \/>\n&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\"&gt;<br \/>\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\"&gt;<\/p>\n<p>&lt;table name=\"goods\" primaryKey=\"ID\" type=\"global\" dataNode=\"dn1\" \/&gt;<\/p>\n<p>&lt;schema name=\"test_db\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" &gt;<\/p>\n<p>&lt;!--\u53ea\u6709\u4e00\u4e2adataNode--&gt;<\/p>\n<p>&lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"test_db\" \/&gt;<\/p>\n<p>&lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" <span style=\"color: #ff0000;\">balance=\"1\" \u00a0<\/span>writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\"<span style=\"color: #000000;\"> switchType=\"1\"<\/span> slav \u00a0 \u00a0 \u00a0 eThreshold=\"100\"&gt;<br \/>\n&lt;heartbeat&gt;select user()&lt;\/heartbeat&gt;<br \/>\n&lt;!--\u65b9\u6848\u4e00 \uff0cM1\u5199 S1 S2\u8bfb --&gt;<br \/>\n&lt;writeHost host=\"hostM1\" url=\"127.0.0.1:3306\" user=\"root\" \u00a0password=\"root@3306\"&gt;<br \/>\n&lt;readHost host=\"hostS1\" url=\"127.0.0.1:3307\" user=\"root\" password=\"root@3307\" \/&gt;<br \/>\n&lt;readHost host=\"hostS2\" url=\"127.0.0.1:3308\" user=\"root\" password=\"root@3308\" \/&gt;<br \/>\n&lt;\/writeHost&gt;<\/p>\n<p>&lt;\/mycat:schema&gt;<\/p><\/blockquote>\n<p><span style=\"color: #ff0000;\">\u8fd9\u91cc\u8981\u914d\u7f6e balance=\u201c1\u201d \uff0c\u9ed8\u8ba4\u4e3a0 \u00a0<\/span><\/p>\n<p><strong>table\u6807\u7b7e\u5c5e\u6027\u8bf4\u660e\uff1a<\/strong><\/p>\n<p>Table \u6807\u7b7e\u5b9a\u4e49\u4e86MyCat\u4e2d\u7684\u903b\u8f91\u8868\uff0c\u6240\u6709\u9700\u8981\u62c6\u5206\u7684\u8868\u90fd\u9700\u8981\u5728\u8fd9\u4e2a\u6807\u7b7e\u4e2d\u5b9a\u4e49\u3002name\u5b9a\u4e49\u903b\u8f91\u8868\u7684\u8868\u540d\uff0c\u8fd9\u4e2a\u540d\u5b57\u5c31\u5982\u540c\u6211\u5728\u6570\u636e\u5e93\u4e2d\u6267\u884ccreate table\u547d\u4ee4\u6307\u5b9a\u7684\u540d\u5b57\u4e00\u6837\uff0c\u540c\u4e2aschema\u6807\u7b7e\u4e2d\u5b9a\u4e49\u7684\u540d\u5b57\u5fc5\u987b\u552f\u4e00\u3002\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a<span style=\"color: #ff0000;\">\u00a0goods<\/span> \u8868\u6765\u6d4b\u8bd5\u8bfb\u5199\u5206\u79bb\u3002<\/p>\n<p><strong>dataHost\u6807\u7b7e\u5c5e\u6027\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>name\u5c5e\u6027<br \/>\n\u552f\u4e00\u6807\u8bc6dataHost\u6807\u7b7e\uff0c\u4f9b\u4e0a\u5c42\u7684\u6807\u7b7e\u4f7f\u7528\u3002<\/li>\n<li>maxCon\u5c5e\u6027<br \/>\n\u6307\u5b9a\u6bcf\u4e2a\u8bfb\u5199\u5b9e\u4f8b\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6807\u7b7e\u5185\u5d4c\u5957\u7684writeHost\u3001readHost\u6807\u7b7e\u90fd\u4f1a\u4f7f\u7528\u8fd9\u4e2a\u5c5e\u6027\u7684\u503c\u6765\u5b9e\u4f8b\u5316\u51fa\u8fde\u63a5\u6c60\u7684\u6700\u5927\u8fde\u63a5\u6570\u3002<\/li>\n<li>minCon\u5c5e\u6027<br \/>\n\u6307\u5b9a\u6bcf\u4e2a\u8bfb\u5199\u5b9e\u4f8b\u8fde\u63a5\u6c60\u7684\u6700\u5c0f\u8fde\u63a5\uff0c\u521d\u59cb\u5316\u8fde\u63a5\u6c60\u7684\u5927\u5c0f\u3002<\/li>\n<li>balance\u5c5e\u6027<br \/>\n\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b\uff0c\u76ee\u524d\u7684\u53d6\u503c\u67093\u79cd\uff1a<br \/>\n1. balance=\u201c0\u201d, \u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u53d1\u9001\u5230\u5f53\u524d\u53ef\u7528\u7684writeHost\u4e0a\u3002<br \/>\n2. balance=\u201c1\u201d\uff0c\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u968f\u673a\u7684\u53d1\u9001\u5230readHost\u3002<br \/>\n3. balance=\u201c2\u201d\uff0c\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u968f\u673a\u7684\u5728writeHost\u3001readhost\u4e0a\u5206\u53d1\u3002<\/li>\n<li>writeType\u5c5e\u6027<br \/>\n\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b\uff0c\u76ee\u524d\u7684\u53d6\u503c\u67093\u79cd\uff1a<br \/>\n1. writeType=\u201c0\u201d, \u6240\u6709\u5199\u64cd\u4f5c\u90fd\u53d1\u9001\u5230\u53ef\u7528\u7684writeHost\u4e0a\u3002<br \/>\n2. writeType=\u201c1\u201d\uff0c\u6240\u6709\u5199\u64cd\u4f5c\u90fd\u968f\u673a\u7684\u53d1\u9001\u5230readHost\u3002<br \/>\n3. writeType=\u201c2\u201d\uff0c\u6240\u6709\u5199\u64cd\u4f5c\u90fd\u968f\u673a\u7684\u5728writeHost\u3001readhost\u5206\u4e0a\u53d1\u3002<\/li>\n<li>dbType\u5c5e\u6027<br \/>\n\u6307\u5b9a\u540e\u7aef\u8fde\u63a5\u7684\u6570\u636e\u5e93\u7c7b\u578b\uff0c\u76ee\u524d\u652f\u6301\u4e8c\u8fdb\u5236\u7684mysql\u534f\u8bae\uff0c\u8fd8\u6709\u5176\u4ed6\u4f7f\u7528JDBC\u8fde\u63a5\u7684\u6570\u636e\u5e93\u3002\u4f8b\u5982\uff1amongodb\u3001oracle\u3001spark\u7b49\u3002<\/li>\n<li>dbDriver\u5c5e\u6027<br \/>\n\u6307\u5b9a\u8fde\u63a5\u540e\u7aef\u6570\u636e\u5e93\u4f7f\u7528\u7684Driver\uff0c\u76ee\u524d\u53ef\u9009\u7684\u503c\u6709native\u548cJDBC\u3002\u4f7f\u7528native\u7684\u8bdd\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u503c\u6267\u884c\u7684\u662f\u4e8c\u8fdb\u5236\u7684mysql\u534f\u8bae\uff0c\u6240\u4ee5\u53ef\u4ee5\u4f7f\u7528mysql\u548cmarib\u3002\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\u5e93\u5219\u9700\u8981\u4f7f\u7528JDBC\u9a71\u52a8\u6765\u652f\u6301\u3002\u5982\u679c\u4f7f\u7528JDBC\u7684\u8bdd\u9700\u8981\u5c06\u7b26\u5408JDBC 4\u6807\u51c6\u7684\u9a71\u52a8JAR\u5305\u653e\u5230MYCAT\\lib\u76ee\u5f55\u4e0b\uff0c\u5e76\u68c0\u67e5\u9a71\u52a8JAR\u5305\u4e2d\u5305\u62ec\u5982\u4e0b\u76ee\u5f55\u7ed3\u6784\u7684\u6587\u4ef6\uff1aMETA-INF\\services\\java.sql.Driver\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u5185\u5199\u4e0a\u5177\u4f53\u7684Driver\u7c7b\u540d\uff0c\u4f8b\u5982\uff1acom.mysql.jdbc.Driver\u3002<\/li>\n<\/ul>\n<h3>4.\u521b\u5efa\u6d4b\u8bd5\u8868goods<\/h3>\n<p>\u767b\u5f553306\u4e3b\u5e93\uff0c\u5728test_db\u4e2d\u521b\u5efa\u6d4b\u8bd5\u8868goods:<\/p>\n<pre class=\"prettyprint linenums\">mysql&gt;use test_db; \r\nmysql&gt;create table goods (id int primary key , gname varchar(50), gprice float , gdesc varchar(200) ) ;\r\n<\/pre>\n<h2>\u4e8c\u3001\u542f\u52a8MyCat\uff0c\u6d4b\u8bd5\u8bfb\u5199\u5206\u79bb\u662f\u5426\u914d\u7f6e\u6210\u529f<\/h2>\n<p>\u64cd\u4f5c\u547d\u4ee4\uff1a.\/bin\/mycat start\/stop\/restart<\/p>\n<p>\u65e5\u5fd7\uff1alogs\/mycat.log \u548c logs\/wrapper.log<\/p>\n<h3>1.\u542f\u52a8mycat<\/h3>\n<pre class=\"prettyprint linenums\">.\/bin\/mycat start\r\n<\/pre>\n<p>\u67e5\u770bwrapper.log\u65e5\u5fd7\uff0c\u5982\u679c\u51fa\u73b0<br \/>\n<span style=\"color: #ff0000;\">Error: Exception thrown by the agent : java.net.MalformedU<\/span><br \/>\n<span style=\"color: #ff0000;\"> RLException: Local host name unknown: java.net.UnknownHostException: iZ2ze1np3s3kfsddhxqr0gZ: iZ2ze1<\/span><br \/>\n<span style=\"color: #ff0000;\"> np3s3kfsddhxqr0gZ: Name or service not known<\/span> \u4e4b\u7c7b\u7684\u9519\u8bef<br \/>\n\u53ef\u80fd\u662f\u7531\u4e8ehosts\u6587\u4ef6\u4e2d iZ2ze1np3s3kfsddhxqr0gZ \u4e3b\u673a\u540d\u6ca1\u6709\u6620\u5c04\u5230127.0.0.1, \u52a0\u4e00\u6761\u8bb0\u5f55\u5c31\u597d<br \/>\nvim \/etc\/hosts<\/p>\n<pre class=\"prettyprint linenums\">127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4\r\n::1         localhost localhost.localdomain localhost6 localhost6.localdomain6\r\n<span style=\"color: #ff0000;\">127.0.0.1   iZ2ze1np3s3kfsddhxqr0gZ<\/span><\/pre>\n<p>\u91cd\u65b0\u542f\u52a8mycat\u5e76\u68c0\u67e5\u65e5\u5fd7<\/p>\n<p>\u67e5\u770b\u670d\u52a1\u6210\u529f\u542f\u52a8\uff1a<\/p>\n<p>ps -ef | grep mycat<\/p>\n<p>\u67e5\u770b\u670d\u52a1\u7aef\u53e3\uff0cmycat\u9ed8\u8ba4\u76d1\u542c8066\u548c9066\uff1a<\/p>\n<p>netstat -ant | grep 8066 \/ 9066<\/p>\n<h3>2.\u6210\u529f\u542f\u52a8\u540e\uff0c\u767b\u5f55mycat\uff0c\u5411goods\u8868\u63d2\u5165\u6d4b\u8bd5\u6570\u636e<\/h3>\n<p><span style=\"color: #ff0000;\">\u5f53\u524d\u64cd\u4f5c\u767b\u5f55\u5230mycat\uff088066\uff09:<\/span><\/p>\n<pre class=\"prettyprint linenums\">#\u8fd9\u91cc\u7684\u7528\u6237\u5bc6\u7801\u662f\u5728 mycat\u4e2d server.xml\u914d\u7f6e\u7684 \u6570\u636e\u5e93 \u4e3a\u903b\u8f91\u6570\u636e\u5e93\r\n mysql -uroot -p123456 -h127.0.0.1 -P8066 test_db\r\n\r\n#\u67e5\u770b\u8868\uff0c\u6211\u4eec\u53ea\u914d\u7f6e\u4e86\u4e00\u4e2agoods\u8868\uff0c\u6240\u4ee5\u53ea\u80fd\u770b\u5230\u4e00\u4e2a\r\nmysql&gt; show tables;\r\n+-------------------+\r\n| Tables in test_db |\r\n+-------------------+\r\n| goods             |\r\n+-------------------+\r\n1 row in set (0.00 sec)\r\n\r\n#\u63d2\u5165\u6d4b\u8bd5\u6570\u636e,<span style=\"color: #ff0000;\">\u4e3a\u4e86\u533a\u522b\u6211\u4eec\u7684\u6570\u636e\u662f\u4ece\u54ea\u91cc\u6765\u7684\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e86@@PORT\u5168\u5c40\u53d8\u91cf\u83b7\u53d6\u4e86mysql\u670d\u52a1\u7aef\u7aef\u53e3\uff0c\u5728select\u7684\u65f6\u5019\u53d1\u73b0\u7aef\u53e3\u4e3a3307<\/span>\r\ninsert into goods (id, gname , gprice , gdesc )  values ( 100,'\u679c\u7c92\u6a59',3.5,@@PORT ); \r\nQuery OK, 1 row affected, 1 warning (0.02 sec)\r\n\r\nmysql&gt; select * from goods;\r\n+-----+-----------+--------+-------+\r\n| id  | gname     | gprice | gdesc |\r\n+-----+-----------+--------+-------+\r\n| 100 | \u679c\u7c92\u6a59    |    3.5 | 3307  |\r\n+-----+-----------+--------+-------+\r\n1 row in set (0.00 sec)\r\nmysql&gt;\r\n<\/pre>\n<p><span style=\"color: #ff0000;\"><strong>\u731c\u60f3\uff1a<\/strong>\u7531\u4e8e\u6211\u4eecmysql\u5df2\u7ecf\u505a\u8fc7\u4e3b\u4ece\u540c\u6b65\uff0c\u6240\u4ee5\u6267\u884cinsert\u4e4b\u540e 3306\u548c3307\u4e2d\u4f1a\u540c\u6b65\u8fd9\u6761\u8bb0\u5f55\uff0c\u4f46\u662f\u7531\u4e8e\u7aef\u53e3\u4e0d\u540c\u6240\u4ee5gdesc\u4e2d\u4f1a\u6709\u5404\u81ea\u7684\u7aef\u53e3<\/span><\/p>\n<p><strong><span style=\"color: #008000;\">\u8bba\u8bc1\uff1a<\/span><\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\u767b\u5f55\u52303306\uff0c\u770b\u770bgoods\u8868\u7684\u5185\u5bb9<\/p>\n<p><span style=\"color: #ff0000;\">\u5f53\u524d\u64cd\u4f5c\u767b\u5f55\u52303306\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">Database changed\r\nmysql&gt; select * from goods;\r\n+-----+-----------+--------+-------+\r\n| id  | gname     | gprice | gdesc |\r\n+-----+-----------+--------+-------+\r\n| 100 | \u679c\u7c92\u6a59    |    3.5 | 3306  |\r\n+-----+-----------+--------+-------+\r\n1 row in set (0.00 sec)\r\n\r\n<\/pre>\n<p>\u518d\u767b\u5f55\u52303307\u67e5\u770bgoods\u8868\u4e2d\u7684\u6570\u636e<\/p>\n<p><span style=\"color: #ff0000;\">\u5f53\u524d\u64cd\u4f5c\u767b\u5f55\u52303307\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">mysql&gt; select * from goods;\r\n+-----+-----------+--------+-------+\r\n| id  | gname     | gprice | gdesc |\r\n+-----+-----------+--------+-------+\r\n| 100 | \u679c\u7c92\u6a59    |    3.5 | 3307  |\r\n+-----+-----------+--------+-------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\n<p>\u518d\u767b\u5f55\u52303308\u67e5\u770bgoods\u8868\u4e2d\u7684\u6570\u636e<\/p>\n<p><span style=\"color: #ff0000;\">\u5f53\u524d\u64cd\u4f5c\u767b\u5f55\u52303308\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">mysql&gt; select * from goods;\r\n+-----+-----------+--------+-------+\r\n| id  | gname     | gprice | gdesc |\r\n+-----+-----------+--------+-------+\r\n| 100 | \u679c\u7c92\u6a59    |    3.5 | 3308  |\r\n+-----+-----------+--------+-------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\n<p>\u6beb\u65e0\u7591\u95ee\uff0c\u521a\u521a\u6211\u4eec\u5728mycat\u63a7\u5236\u53f0\u67e5\u8be2\u5230\u7684\u6570\u636e\uff0c\u6765\u6e90\u4e3a3307\u4e2d\u7684\u6570\u636e\uff01<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u505c\u63893307\u670d\u52a1\uff0c\u518d\u67e5\u8be2goods\u8868<\/p>\n<pre class=\"prettyprint linenums\">[root@iZ2ze1np3s3kfsddhxqr0gZ software]# sh mysqlStop.sh 3307\r\n<\/pre>\n<p><span style=\"color: #ff0000;\">\u56de\u5230mycat\uff088066\uff09\u63a7\u5236\u53f0\uff0c\u67e5\u8be2goods\u8868\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">mysql&gt; select * from goods;\r\n+-----+-----------+--------+-------+\r\n| id  | gname     | gprice | gdesc |\r\n+-----+-----------+--------+-------+\r\n| 100 | \u679c\u7c92\u6a59    |    3.5 | 3308  |\r\n+-----+-----------+--------+-------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\n<p>\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><a href=\"http:\/\/www.chenweikang.top\/wp-content\/uploads\/2017\/08\/mycat-wr1.png\" class=\"gallery_colorbox\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-406\" src=\"http:\/\/www.chenweikang.top\/wp-content\/uploads\/2017\/08\/mycat-wr1.png\"  alt=\"\" width=\"575\" height=\"310\" srcset=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2017\/08\/mycat-wr1.png 575w, https:\/\/www.chenweikang.top\/wp-content\/uploads\/2017\/08\/mycat-wr1-300x162.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/a><\/p>\n<h3>\u7ed3\u8bba\uff1a\u7531\u4e8e\u6211\u4eec\u5728writeHost \u914d\u7f6e\u4e86\u4e24\u4e2areadHost \uff0cmycat\u5728\u67e5\u8be2\u7684\u65f6\u5019\u4f18\u5148\u67e5\u8be2hostS1(3307)\uff0c\u5f53hostS1\u4e0d\u53ef\u7528\u65f6\uff0c\u81ea\u52a8\u5207\u6362\u5230hsotS2(3308)\u3002\u8be5\u65b9\u6848\u7f3a\u70b9\uff0c\u5f53\u5199\u5e93hostM1\u6302\u6389\uff0chostS1\u3001hostS2\u5747\u4e0d\u80fd\u6b63\u5e38\u670d\u52a1\u3002<\/h3>\n<h3>\u53e6\u4e00\u79cd\u914d\u7f6e\u65b9\u5f0f---\u00a0\u4e0d\u4f7f\u7528mycay\u6258\u7ba1\u4e3b\u4ece\u5207\u6362<\/h3>\n<blockquote><p>&lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"1\" \u00a0writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\" slav \u00a0 \u00a0 \u00a0 eThreshold=\"100\"&gt;<\/p>\n<p>&lt;heartbeat&gt;select user()&lt;\/heartbeat&gt;<\/p>\n<p>&lt;!-- \u914d\u7f6e\u4e00\u4e2a\u7528\u4e8e\u5199\u7684\u5e93 --&gt;<\/p>\n<p>&lt;writeHost host=\"hostM1\" url=\"127.0.0.1:3306\" user=\"root\" password=\"root@3306\"&gt;<\/p>\n<p>&lt;!-- \u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u7528\u4e8e\u8bfb\u7684\u5e93 --&gt;<\/p>\n<p>&lt;writeHost host=\"hostS1\" url=\"127.0.0.1:3307\" user=\"root\" password=\"root@3307\" \/&gt;<\/p>\n<p>&lt;writeHost host=\"hostS2\" url=\"127.0.0.1:3308\" user=\"root\" password=\"root@3308\" \/&gt;<br \/>\n&lt;\/writeHost&gt;<\/p><\/blockquote>\n<p><span style=\"color: #ff0000;\">\u8fd9\u79cd\u65b9\u5f0f\u4e5f\u662f\u4f18\u5148\u5c06M1\u4f5c\u4e3a\u5199\uff0cS1\u3001S2\u4f5c\u4e3a\u968f\u673a\u8bfb\uff0c\u5f53M1\u6302\u6389 S1\u3001S2\u80fd\u7ee7\u7eed\u4f7f\u7528\uff0c\u4e14S1\u53d8\u4e3a\u5199\u5e93\uff0cS2\u53d8\u4e3a\u8bfb\u5e93\uff0c\u5f53M1\u6062\u590d\u540e\uff0cM1\u53d8\u4e3a\u8bfb\u5e93\uff0cS1\u4ecd\u7136\u4e3a\u5199\u5e93\u4e0d\u53d8\uff0c\u7531\u4e8e\u6b64\u65f6\u5e76\u6ca1\u6709\u4f7f\u7528mycat\u6258\u7ba1\u4e3b\u4ece\u5207\u6362\uff0c\u6240\u4ee5\u5f53M1\u6302\u6389\uff0cS1\u4f5c\u4e3a\u5199\u5e93\u65b0\u589e\u7684\u6570\u636e\u4e0d\u4f1a\u540c\u6b65\u5230S2\uff0c\u5bfc\u81f4\u8bfb\u53d6S2\u5e93\u91cc\u7684\u6570\u636e\u53ef\u80fd\u4e3a\u65e7\u6570\u636e\uff01<\/span><\/p>\n<p>\u5207\u6362\u4e3b\u673a\u7684\u8bb0\u5f55\u5728\u00a0conf\/dnindex.properties \uff0c\u67e5\u770b\u8be5\u6587\u4ef6\uff1a<\/p>\n<p>#update<br \/>\n#Tue Aug 15 14:27:34 CST 2017<br \/>\nlocalhost1=1<\/p>\n<p>\u6b64\u65f6\u5e94\u5f53\u91cd\u65b0\u914d\u7f6e\u4e3b\u4ece\u540c\u6b65\u670d\u52a1\uff0c\u5c06S1\u53d8\u4e3a\u4e3b\uff0cM1\u53d8\u4e3a\u4ece\u52a0\u5165\u5230\u4ece\u5e93\u540e\uff01\u6216\u8005\u5c06M1\u540c\u6b65\u5230\u6700\u65b0\uff0cmycat\u4e2d\u6267\u884c\u5207\u6362\u547d\u4ee4switch @@datasource localhost1:0<\/p>\n<h3>\u53e6\u4e00\u79cd\u914d\u7f6e\u65b9\u5f0f--\u4f7f\u7528mycat\u6258\u7ba1\u4e3b\u4ece\u5207\u6362<\/h3>\n<blockquote><p>&lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\" \u00a0writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"2\" slav \u00a0 \u00a0 \u00a0 eThreshold=\"100\"&gt;<\/p>\n<p>&lt;heartbeat&gt;show slave status&lt;\/heartbeat&gt;<\/p>\n<p>&lt;!-- \u914d\u7f6e\u4e00\u4e2a\u7528\u4e8e\u5199\u7684\u5e93 --&gt;<\/p>\n<p>&lt;writeHost host=\"hostM1\" url=\"127.0.0.1:3306\" user=\"root\" password=\"root@3306\"&gt;<\/p>\n<p>&lt;!-- \u53ef\u4ee5\u914d\u7f6e\u591a\u4e2a\u7528\u4e8e\u8bfb\u7684\u5e93 --&gt;<\/p>\n<p>&lt;writeHost host=\"hostS1\" url=\"127.0.0.1:3307\" user=\"root\" password=\"root@3307\" \/&gt;<\/p>\n<p>&lt;writeHost host=\"hostS2\" url=\"127.0.0.1:3308\" user=\"root\" password=\"root@3308\" \/&gt;<br \/>\n&lt;\/writeHost&gt;<\/p><\/blockquote>\n<p><span style=\"color: #ff0000;\">\u5f53\u914d\u7f6e\u4e86Mycat\u6258\u7ba1\u4e3b\u4ece\uff0c\u4e14 balance=\"2\" \u6240\u6709\u8bfb\u64cd\u4f5c\u5728\u4e09\u4e2a\u4e3b\u673a\u968f\u673a\u8fdb\u884c\uff0c\u5199\u64cd\u4f5c\u5728M1\u8fdb\u884c\u3002\u5f53M1\u6302\u6389\uff0c\u81ea\u52a8\u5207\u6362S1\u4e3a\u4e3b\u5e93<\/span><\/p>\n<h2>\u9644\u5f55<\/h2>\n<ul>\n<li>Mycat \u6350\u8d60\u5730\u5740 \uff1a<a href=\"http:\/\/www.mycat.io\/donate.html\" target=\"_blank\" rel=\"noopener\">http:\/\/www.mycat.io\/donate.html<\/a><\/li>\n<li>Mycat \u5b98\u65b1\u7f51\u7ad9\uff1a<a href=\"http:\/\/www.mycat.io\/\" target=\"_blank\" rel=\"noopener\">http:\/\/www.mycat.io\/<\/a><\/li>\n<li>Mycat \u6e90\u7801\uff1a<a href=\"https:\/\/github.com\/MyCATApache\/Mycat-Server\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/MyCATApache\/Mycat-Server<\/a><\/li>\n<li>Mycat \u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/github.com\/MyCATApache\/Mycat-download\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/MyCATApache\/Mycat-download<\/a><\/li>\n<\/ul>\n<h2>\u5176\u4ed6\u5b9e\u9a8c<\/h2>\n<ul>\n<li><a href=\"http:\/\/www.chenweikang.top\/mycat%E5%AE%9E%E9%AA%8C%EF%BC%881%EF%BC%89-%E5%8D%95%E4%B8%AA%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2%E5%A4%9A%E4%B8%AAmysql\/\">mycat\u5b9e\u9a8c\uff081\uff09-\u5355\u4e2a\u670d\u52a1\u5668\u90e8\u7f72\u591a\u4e2amysql<\/a><\/li>\n<li><a href=\"http:\/\/www.chenweikang.top\/mycat%E5%AE%9E%E9%AA%8C%EF%BC%882%EF%BC%89-%E9%85%8D%E7%BD%AEmysql%E4%B8%BB%E4%BB%8E%E5%90%8C%E6%AD%A5\/\">mycat\u5b9e\u9a8c\uff082\uff09-\u914d\u7f6emysql\u4e3b\u4ece\u540c\u6b65<\/a><\/li>\n<li><a href=\"http:\/\/www.chenweikang.top\/mycat%E5%AE%9E%E9%AA%8C%EF%BC%883%EF%BC%89-%E7%AE%80%E5%8D%95%E9%85%8D%E7%BD%AEmycat%EF%BC%8C%E5%AE%9E%E7%8E%B0%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB\/\">mycat\u5b9e\u9a8c\uff083\uff09-\u7b80\u5355\u914d\u7f6emycat\uff0c\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb<\/a><\/li>\n<li><a href=\"http:\/\/www.chenweikang.top\/mycat%E5%AE%9E%E9%AA%8C%EF%BC%884%EF%BC%89-mycat%E6%95%B0%E6%8D%AE%E5%88%86%E7%89%87%E6%B5%8B%E8%AF%95\/\">mycat\u5b9e\u9a8c\uff084\uff09-mycat\u6570\u636e\u5206\u7247\u6d4b\u8bd5<\/a><\/li>\n<\/ul>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.chenweikang.top\">\u5de6\u624b\u4ee3\u7801\u53f3\u624b\u8bd7<\/a> &raquo; <a href=\"https:\/\/www.chenweikang.top\/?p=401\">Mycat\u4e3b\u4ece\u540c\u6b65\u3001\u8bfb\u5199\u5206\u79bb\u3001\u5206\u5e93\u5206\u8868\uff083\uff09- \u7b80\u5355\u914d\u7f6eMycat\uff0c\u5b9e\u73b0\u8bfb\u5199\u5206\u79bb<\/a><\/p><div class=\"__youshang\">\r\n            <div id=\"__youshang_popup\" class=\"wechat popup\" style=\"display: none;\">\r\n                <div class=\"head\">~\u8c22\u8c22\u6253\u8d4f~<\/div>\r\n                <div class=\"qrcode\"><div class=\"qrcode-li wechat\" ><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/wexin.png\" \/><\/div><div class=\"qrcode-li alipay\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-pay.png\" \/><\/div><div class=\"qrcode-li hongbao\" style=\"display:none;\"><img src=\"https:\/\/www.chenweikang.top\/wp-content\/uploads\/2019\/07\/ali-hongbao.png\" \/><\/div><\/div>\r\n                <ul class=\"platform\"><li class=\"icon-wechat active\" data-bg-color=\"#05af4e\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-alipay \" data-bg-color=\"#00a2ea\" data-thanks=\"~\u8c22\u8c22\u6253\u8d4f~\"><\/li><li class=\"icon-hongbao \" data-bg-color=\"#dd5746\" data-thanks=\"<p>\u626b\u7801\u9886\u7ea2\u5305<\/p><p style='margin-top: 24px;'>\uff08\u4f59\u989d\u5b9d\u652f\u4ed8\u65f6\u53ef\u62b5\u73b0\uff09<\/p>\"><\/li><\/ul>\r\n            <\/div>\r\n            <a href=\"javascript:void(0);\" id=\"__youshang_btn\">\u8d4f<\/a>\r\n        <\/div>","protected":false},"excerpt":{"rendered":"<p>MyCat\u662f\u57fa\u4e8e\u963f\u91cc\u5df4\u5df4\u7684\u5f00\u6e90\u4ea7\u54c1CoBar\u6f14\u53d8\u800c\u6765\uff0c\u4ee5\u4ee3\u66ff\u6602\u8d35\u7684oracle\u7684MySQL\u96c6\u7fa4\u7684\u4e2d\u95f4\u4ef6\u3002\u5173\u4e8eM [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":406,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[46,45],"class_list":["post-401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database","tag-mycat","tag-45"],"_links":{"self":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=401"}],"version-history":[{"count":0,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/posts\/401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=\/wp\/v2\/media\/406"}],"wp:attachment":[{"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenweikang.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}