{"id":944,"date":"2018-08-10T15:21:46","date_gmt":"2018-08-10T07:21:46","guid":{"rendered":"https:\/\/blog.jsjs.org\/?p=944"},"modified":"2018-08-10T15:21:46","modified_gmt":"2018-08-10T07:21:46","slug":"mycat%e7%ae%80%e5%8d%95%e4%bd%bf%e7%94%a8%e4%b8%8e%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/blog.jsjs.org\/?p=944","title":{"rendered":"MyCat\u7b80\u5355\u4f7f\u7528\u4e0e\u914d\u7f6e"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u57fa\u672c\u914d\u7f6e<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>1 . \u5728<code>mycat\/conf<\/code>\u76ee\u5f55\u4e0b\uff0cMyCat\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\uff1aschema.xml<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?>\n&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;!-- \u5b9a\u4e49\u4e00\u4e2aMyCat\u7684\u6a21\u5f0f\uff0c\u903b\u8f91\u6570\u636e\u5e93\u540d\u79f0TestDB -->\n        &lt;!-- \u201ccheckSQLschema\u201d\uff1a\u63cf\u8ff0\u7684\u662f\u5f53\u524d\u7684\u8fde\u63a5\u662f\u5426\u9700\u8981\u68c0\u6d4b\u6570\u636e\u5e93\u7684\u6a21\u5f0f -->\n        &lt;!-- \u201csqlMaxLimit\u201d\uff1a\u8868\u793a\u8fd4\u56de\u7684\u6700\u5927\u7684\u6570\u636e\u91cf\u7684\u884c\u6570 -->\n        &lt;!-- \u201cdataNode=\"dn1\"\u201d\uff1a\u8be5\u64cd\u4f5c\u4f7f\u7528\u7684\u6570\u636e\u8282\u70b9\u662fdn1\u7684\u903b\u8f91\u540d\u79f0 -->\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn1\"\/>\n        &lt;!-- \u5b9a\u4e49\u6570\u636e\u7684\u64cd\u4f5c\u8282\u70b9 -->\n        &lt;!-- \u201cdataHost=\"localhost1\"\u201d\uff1a\u5b9a\u4e49\u6570\u636e\u8282\u70b9\u7684\u903b\u8f91\u540d\u79f0 -->\n        &lt;!-- \u201cdatabase=\"mldn\"\u201d\uff1a\u5b9a\u4e49\u6570\u636e\u8282\u70b9\u8981\u4f7f\u7528\u7684\u6570\u636e\u5e93\u540d\u79f0 -->\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"mldn\" \/>\n        &lt;!-- \u5b9a\u4e49\u6570\u636e\u8282\u70b9\uff0c\u5305\u62ec\u4e86\u5404\u79cd\u903b\u8f91\u9879\u7684\u914d\u7f6e -->\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"0\" writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n            &lt;!-- \u914d\u7f6e\u771f\u5b9eMySQL\u4e0eMyCat\u7684\u5fc3\u8df3 -->\n            &lt;heartbeat>select user()&lt;\/heartbeat>\n            &lt;!-- \u914d\u7f6e\u771f\u5b9e\u7684MySQL\u7684\u8fde\u63a5\u8def\u5f84 -->\n            &lt;writeHost host=\"hostM1\" url=\"192.168.1.128:3306\" user=\"root\" password=\"123456\">&lt;\/writeHost>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>2 . <code>dataHost<\/code>\u6807\u7b7e\u4e0a\u5c5e\u6027\u91ca\u4e49\uff1a\n<ul><li>\n<code>balance<\/code>:\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b\n<ul><li>0\uff1a\u4e0d\u5f00\u542f\u8bfb\u5199\u5206\u79bb\u673a\u5236\uff0c\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u53d1\u9001\u5230\u5f53\u524d\u53ef\u7528\u7684writeHost\u4e0a<\/li><li>1\uff1a\u5168\u90e8\u7684readHost\u4e0estand by writeHost\u53c2\u4e0eselect\u8bed\u53e5\u7684\u8d1f\u8f7d\u5747\u8861\uff0c<\/li><li>2\uff1a\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u968f\u673a\u5728writeHost\u3001readHost\u4e0a\u5206\u53d1<\/li><li>3\uff1a\u6240\u6709\u8bfb\u8bf7\u6c42\u968f\u673a\u5206\u53d1\u5230writeHost\u5bf9\u5e94\u7684readHost\u6267\u884c\uff0cwriteHost\u4e0d\u8d1f\u62c5\u8bfb\u538b\u529b<\/li><\/ul>\n<\/li><li>\n<code>writeType<\/code>:\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b\n<ul><li>0\uff1a\u6240\u6709\u5199\u64cd\u4f5c\u53d1\u9001\u5230\u914d\u7f6e\u7684\u7b2c\u4e00\u4e2awriteHost\uff0c\u5f53\u7b2c\u4e00\u4e2awriteHost\u5b95\u673a\u65f6\uff0c\u5207\u6362\u5230\u7b2c\u4e8c\u4e2awriteHost\uff0c\u91cd\u65b0\u542f\u52a8\u540e\u4ee5\u5207\u6362\u540e\u7684\u4e3a\u51c6\uff0c\u5207\u6362\u8bb0\u5f55\u5728\u914d\u7f6e\u6587\u4ef6\uff1a<code>dnindex.properties<\/code>\u4e2d<\/li><li>1\uff1a\u6240\u6709\u5199\u64cd\u4f5c\u90fd\u968f\u53d1\u9001\u5230\u914d\u7f6e\u7684writeHost<\/li><li>2\uff1a\u5c1a\u672a\u5b9e\u73b0<\/li><\/ul>\n<\/li><li>\n<code>switchType<\/code>:\u5207\u6362\u65b9\u5f0f\n<ul><li>-1\uff1a\u4e0d\u81ea\u52a8\u5207\u6362<\/li><li>1\uff1a\u81ea\u52a8\u5207\u6362\uff08\u9ed8\u8ba4\uff09<\/li><li>2\uff1a\u57fa\u4e8eMySql\u4e3b\u4ece\u540c\u6b65\u7684\u72b6\u6001\u6765\u51b3\u5b9a\u662f\u5426\u5207\u6362<\/li><\/ul>\n<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bfb\u5199\u5206\u79bb<\/h2>\n\n\n\n<h5 class=\"wp-block-heading\">\u4e00. MySQL\u4e3b\u4ece\u914d\u7f6e<\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li>1 . \u524d\u63d0\uff1a\u591a\u53f0MySQL\u670d\u52a1\u5668\u4e3b\u673a\u7684\u65f6\u95f4\u662f\u540c\u6b65\u7684\uff0c\u5426\u5219\u65e0\u6cd5\u5b9e\u73b0\u4e3b\u4ece\u914d\u7f6e<\/li><li>2 . <strong>MASTER<\/strong>\u4fee\u6539MySQL\u914d\u7f6e\u6587\u4ef6<code>vim \/usr\/local\/mysql\/my.cnf<\/code><\/li><\/ul>\n\n\n\n<p>log-bin=mysql-bin-1  :  \u8868\u793a\u914d\u7f6e\u540c\u6b65\u7684bin\u7684\u6587\u4ef6\u540d\u79f0\uff0c\u4e0d\u540c\u7684\u4e3b\u4ece\u5173\u7cfb\u7ec4\uff0c\u540d\u79f0\u4e0d\u540c<br\/>\nserver_id=196  \uff1a  \u8868\u793aMySQL\u670d\u52a1\u7684\u7f16\u53f7\uff0c\u8fd9\u4e2a\u7f16\u53f7\u4e00\u822c\u53d6IP\u7684\u6700\u540e\u4e00\u4f4d\uff0c\u4e5f\u53ef\u81ea\u5b9a\u4e49<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>3 . <strong>MASTER<\/strong>\u542f\u52a8MySQL\u670d\u52a1<code>nohup mysqld_safe --user=root > \/dev\/null 2>&amp;1 &amp;<\/code>\n<\/li><li>4 . <strong>MASTER<\/strong> \u767b\u9646MySQL\u6570\u636e\u5e93\uff1a<code>mysql -uroot -p123456<\/code>,\u67e5\u770bmaster\u72b6\u6001<code>show master stats;<\/code>\n<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5176\u4e2d<br\/>\nFile(tid_set)  :  \u8868\u793a\u4e3b\u673a\u540d\u79f0\uff08mysql-bin-1.000001\uff09<br\/>\nPosition  :  \u8868\u793a\u540c\u6b65\u7684\u8282\u70b9\u4f4d\u7f6e<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>5 . <strong>MASTER<\/strong>\u5efa\u7acb\u540c\u6b65\u7528\u6237\uff1async_user<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT REPLICCATION SLAVE,REPLICATION CLIENT ON *.* TO 'sync_user'@'192.168.1.%' IDENTIFIED BY '123456';\nflush privileges;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>6 . <strong>SLAVE<\/strong>\u4fee\u6539MySQL\u914d\u7f6e\u6587\u4ef6<code>vim \/usr\/local\/mysql\/my.cnf<\/code>\n<\/li><\/ul>\n\n\n\n<p>log-bin=mysql-bin-1  :  \u8868\u793a\u914d\u7f6e\u540c\u6b65\u7684bin\u7684\u6587\u4ef6\u540d\u79f0\uff0c\u4e0d\u540c\u7684\u4e3b\u4ece\u5173\u7cfb\u7ec4\uff0c\u540d\u79f0\u4e0d\u540c<br\/>\nserver_id=168  \uff1a  \u8868\u793aMySQL\u670d\u52a1\u7684\u7f16\u53f7\uff0c\u8fd9\u4e2a\u7f16\u53f7\u4e00\u822c\u53d6IP\u7684\u6700\u540e\u4e00\u4f4d\uff0c\u4e5f\u53ef\u81ea\u5b9a\u4e49<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>7 . <strong>MASTER<\/strong>\/<strong>SLAVE<\/strong>  :  \u82e5\u670d\u52a1\u5df2\u7ecf\u542f\u52a8\uff0c\u9700\u8981\u5220\u9664\u81ea\u52a8\u914d\u7f6e\u7684\u7f16\u53f7\u6587\u4ef6\uff0c\u5426\u5219\u65e0\u6cd5\u540c\u6b65<code>rm \/usr\/local\/mysql\/data\/auto.cnf<\/code>\n<\/li><li>8 . <strong>SLAVE<\/strong> \u542f\u52a8MySQL\u670d\u52a1<code>nohup mysqld_safe --user=root > \/dev\/null 2>&amp;1 &amp;<\/code>\n<\/li><li>9 . <strong>SLAVE<\/strong> \u767b\u9646MySQL\u6570\u636e\u5e93\uff1a<code>mysql -uroot -p123456<\/code>\n<\/li><li>10 . <strong>SLAVE<\/strong>\u8fdb\u884c\u4e3b\u4ece\u5173\u7cfb\u914d\u7f6e<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u82e5\u6b64\u65f6\u5df2\u7ecf\u542f\u52a8\u4e86\u4ece\u4e3b\u673a\uff0c\u5fc5\u987b\u5148\u505c\u6b62\uff1a<code>stop slave;<\/code><\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u505c\u6b62\u4e4b\u540e\u8fd8\u60f3\u91cd\u65b0\u542f\u52a8\uff0c\u5fc5\u987b\u6e05\u695a\u6240\u6709\u7684\u65e5\u5fd7\u4fe1\u606f\uff1a  <code>flush logs;<\/code>\n<\/li><li>\u5b9a\u4e49master\u4e3b\u673a\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>change master to master_host='192.168.1.128',master_user='sync_user',master_password='123456',master_log_file='mysql-bin-1.000001',master_log_pos=435 ;\n<\/code><\/pre>\n\n\n\n<p><code>master_host<\/code>\u8868\u793amast\u7684\u4e3b\u673aip<br\/>\n<code>master_user<\/code>\u8868\u793a\u53ef\u540c\u6b65\u7684\u8d26\u53f7<br\/>\n<code>master_password<\/code>\u8868\u793a\u540c\u6b65\u8d26\u53f7\u7684\u5bc6\u7801<br\/>\n<code>master_log_file<\/code>\u8868\u793a<strong>MASTER<\/strong><code>show master stats;<\/code>\u67e5\u770b\u65f6\u7684File(tid_set)<br\/>\n<code>master_log_pos<\/code>\u8868\u793a<strong>MASTER<\/strong><code>show master stats;<\/code>\u67e5\u770b\u65f6\u7684Position<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u542f\u52a8slave\uff1a<code>start slave;<\/code>\n<\/li><li>\u67e5\u8be2\u5f53\u524d\u4ece\u4e3b\u673a\u72b6\u6001\uff1a<code>show slave status\\G;<\/code>\n<\/li><li>\u82e5\u51fa\u73b0\u4ee5\u4e0b\u4ee3\u7801\u8868\u793a\u5df2\u7ecf\u542f\u52a8\u5b8c\u6210<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Slave_IO_Running:YES\nSlave_SQL_Running:Yes\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u4e8c. MyCat\u8bfb\u5199\u5206\u79bb\u914d\u7f6e<\/h5>\n\n\n\n<ul class=\"wp-block-list\"><li>1 . \u4fee\u6539MyCat\u7684<code>schema.xml<\/code>\u6587\u4ef6<code>vim \/usr\/local\/mycat\/conf\/schema.xml<\/code>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?>\n&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;!-- \u5b9a\u4e49\u4e00\u4e2aMyCat\u7684\u6a21\u5f0f\uff0c\u903b\u8f91\u6570\u636e\u5e93\u540d\u79f0TestDB -->\n        &lt;!-- \u201ccheckSQLschema\u201d\uff1a\u63cf\u8ff0\u7684\u662f\u5f53\u524d\u7684\u8fde\u63a5\u662f\u5426\u9700\u8981\u68c0\u6d4b\u6570\u636e\u5e93\u7684\u6a21\u5f0f -->\n        &lt;!-- \u201csqlMaxLimit\u201d\uff1a\u8868\u793a\u8fd4\u56de\u7684\u6700\u5927\u7684\u6570\u636e\u91cf\u7684\u884c\u6570 -->\n        &lt;!-- \u201cdataNode=\"dn1\"\u201d\uff1a\u8be5\u64cd\u4f5c\u4f7f\u7528\u7684\u6570\u636e\u8282\u70b9\u662fdn1\u7684\u903b\u8f91\u540d\u79f0 -->\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn1\"\/>\n        &lt;!-- \u5b9a\u4e49\u4e2a\u6570\u636e\u7684\u64cd\u4f5c\u8282\u70b9\uff0c\u4ee5\u540e\u8fd9\u4e2a\u8282\u70b9\u4f1a\u8fdb\u884c\u4e00\u4e9b\u5e93\u8868\u5206\u79bb\u4f7f\u7528 -->\n        &lt;!-- \u201cdataHost=\"localhost1\"\u201d\uff1a\u5b9a\u4e49\u6570\u636e\u8282\u70b9\u7684\u903b\u8f91\u540d\u79f0 -->\n        &lt;!-- \u201cdatabase=\"test\"\u201d\uff1a\u5b9a\u4e49\u6570\u636e\u8282\u70b9\u8981\u4f7f\u7528\u7684\u6570\u636e\u5e93\u540d\u79f0 -->\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"test\" \/>\n        &lt;!-- \u5b9a\u4e49\u6570\u636e\u8282\u70b9\uff0c\u5305\u62ec\u4e86\u5404\u79cd\u903b\u8f91\u9879\u7684\u914d\u7f6e -->\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"0\" writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n            &lt;!-- \u914d\u7f6e\u771f\u5b9eMySQL\u4e0eMyCat\u7684\u5fc3\u8df3 -->\n            &lt;heartbeat>select user()&lt;\/heartbeat>\n            &lt;!-- \u914d\u7f6e\u771f\u5b9e\u7684MySQL\u7684\u8fde\u63a5\u8def\u5f84 -->\n            &lt;writeHost host=\"hostMaster\" url=\"192.168.1.196:3306\" user=\"root\" password=\"123456\">\n                &lt;readHost host=\"hostSlave\" url=\"192.168.1.168:3306\" user=\"root\" password=\"123456\"\/>\n            &lt;\/writeHost>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>2 . \u5bf9\u4e8e\u8bfb\u5199\u5206\u79bb\u7684\u914d\u7f6e\u4e2d\uff1a\u8bbe\u7f6ereadHost\u8bfb\u53d6\uff1a<code>balance=3<\/code>\uff0c\u8bbe\u7f6ewriteHost\u4e0eReadHost\u5171\u540c\u5206\u62c5\u8bfb\u53d6\uff1a<code>balance=2<\/code>\n<\/li><li>3 . \u542f\u52a8MyCat\u670d\u52a1\uff1a<code>\/usr\/local\/mycat\/bin\/mycat console<\/code>\n<\/li><li>4 . \u6b64\u65f6\u5c31\u5b8c\u6210\u4e86MyCat\u8bfb\u5199\u5206\u79bb\u7684\u76f8\u5173\u914d\u7f6e<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5782\u76f4\u5206\u5e93<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">\u5782\u76f4\u5206\u5e93\u5b9e\u9645\u4e0a\u5c31\u662f\u8fdb\u884c\u591a\u8868\u5206\u5e93\u7ba1\u7406<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>1 . \u5206\u522b\u5728\u591a\u53f0MySQL\u4e3b\u673a\u4e0a\u8fdb\u884c\u591a\u4e2a\u8868\u7684\u521b\u5efa<\/li><li>2 . \u4fee\u6539MyCat\u7684\u914d\u7f6e\u6587\u4ef6<code>vim \/usr\/local\/mycat\/conf\/schema.xml<\/code>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?>\n&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;schema name=\"TESTDB1\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn1\"\/>\n        &lt;schema name=\"TESTDB2\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn2\"\/>\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"db1\" \/>\n        &lt;dataNode name=\"dn2\" dataHost=\"localhost2\" database=\"db2\" \/>\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host1\" url=\"192.168.1.199:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost2\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host2\" url=\"192.168.1.166:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>3 . \u4fee\u6539MyCat\u7528\u6237\u914d\u7f6e\u6587\u4ef6\uff0c\u5c06\u591a\u4e2a\u6570\u636e\u5e93\u914d\u7f6e\u5230<code>server.xml<\/code>\u4e2d<code>vim \/usr\/local\/mycat\/conf\/server.xml<\/code>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;property name=\"schemas\">TESTDB1,TESTDB2&lt;\/property>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>4 . \u542f\u52a8MyCat\u670d\u52a1<code>\/usr\/local\/mycat\/bin\/mycat console<\/code>\n<\/li><li>5 . \u6b64\u65f6\u5373\u5b8c\u6210\u4e86\u5782\u76f4\u5206\u5e93\uff0c\u6570\u636e\u64cd\u4f5c\u65f6\u9700\u8981\u6307\u5b9a\u5177\u4f53\u64cd\u4f5c\u7684\u662f\u54ea\u4e00\u4e2a\u6570\u636e\u5e93<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5168\u5c40\u8868<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>1 . \u5168\u5c40\u8868\u7684\u4f5c\u7528\uff1a\u53ef\u5145\u5f53\u6570\u636e\u5b57\u5178\u8868\uff0c\u8fd9\u5f20\u6570\u636e\u8868\u4f1a\u5728\u6240\u6709\u7684\u6570\u636e\u5e93\u4e2d\u5b58\u5728\uff0c\u4f46\u5bf9\u5916\u800c\u8a00\uff0c\u53ea\u662f\u4e00\u4e2a\u903b\u8f91\u6570\u636e\u5e93\u5b58\u5728\u7684\u6570\u636e\u8868\uff0c\u5f53\u5bf9\u8be5\u8868\u8fdb\u884c\u53d8\u66f4\u64cd\u4f5c\u65f6\uff0c\u6240\u6709\u6570\u636e\u5e93\u7684\u8be5\u8868\u90fd\u4f1a\u53d1\u751f\u76f8\u5e94\u7684\u53d8\u5316<\/li><li>2 . \u5728\u591a\u53f0MySQL\u4e3b\u673a\u4e0a\u5206\u522b\u5efa\u7acb\u5404\u81ea\u7684\u6570\u636e\u5b57\u5178\u8868<\/li><li>3 . \u4fee\u6539MyCat\u7684\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6<code>vim \/usr\/local\/mycat\/conf\/schema.xml<\/code>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\">\n                &lt;table name=\"dict\" primaryKey=\"did\" type=\"global\" dataNode=\"dn1,dn2\"\/>\n        &lt;\/schema>\n        &lt;schema name=\"TESTDB1\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn1\"\/>\n        &lt;schema name=\"TESTDB2\" checkSQLschema=\"false\" sqlMaxLimit=\"100\" dataNode=\"dn2\"\/>\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"db1\" \/>\n        &lt;dataNode name=\"dn2\" dataHost=\"localhost2\" database=\"db2\" \/>\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host1\" url=\"192.168.1.199:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost2\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host2\" url=\"192.168.1.166:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>4 . \u4fee\u6539MyCat\u7684\u7528\u6237\u914d\u7f6e\u6587\u4ef6<code>vim \/usr\/local\/mycat\/conf\/server.xml<\/code>\uff0c\u5c06<code>schema.xml<\/code>\u914d\u7f6e\u7684\u6240\u6709\u903b\u8f91\u6570\u636e\u5e93\uff0c\u914d\u7f6e\u5230\u8be5\u914d\u7f6e\u6587\u4ef6\u4e2d<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;property name=\"schemas\">TESTDB1,TESTDB2,TESTDB&lt;\/property>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>5 . \u542f\u52a8MyCat\u670d\u52a1<code>\/usr\/local\/mycat\/bin\/mycat console<\/code>\n<\/li><li>6 . \u6b64\u65f6\u5c31\u5b8c\u6210\u4e86\u5168\u5c40\u8868\u7684\u914d\u7f6e\uff0c\u6b64\u65f6\u53ea\u8981\u5bf9TESTDB\u8be5\u903b\u8f91\u6570\u636e\u5e93\u8fdb\u884cdict\u8868\u7684\u66f4\u65b0\u6216\u63d2\u5165\u64cd\u4f5c\uff0c\u6240\u6709\u7684\u5176\u4ed6\u6570\u636e\u5e93\uff08TESTDB1\uff0cTESTDB2\uff09\u4e0a\u7684dict\u8868\u90fd\u4f1a\u5f97\u5230\u66f4\u65b0<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u6c34\u5e73\u5206\u5e93<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>\n\u4e00 .\u5e38\u7528\u6c34\u5e73\u5206\u5e93\n<\/li><li>\u6c34\u5e73\u5206\u5e93\u6307\u7684\u662f\u5c06\u4e00\u4e2a\u6570\u636e\u91cf\u5e9e\u5927\u7684\u6570\u636e\u8868\u5206\u522b\u4fdd\u5b58\u5230\u4e0d\u540c\u7684\u6570\u636e\u5e93\u91cc\uff0c\u5373\uff1a\u73b0\u5728\u6709\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u8fd9\u4e2a\u5e93\u4fdd\u5b58\u540c\u6837\u7ed3\u6784\u7684\u6570\u636e\u8868\uff0c\u8fd9\u4e9b\u6570\u636e\u6839\u636eMyCat\u7684\u7b97\u6cd5\uff0c\u5206\u522b\u4fdd\u5b58\u5230\u7b26\u5408\u81ea\u8eab\u8981\u6c42\u7684\u6570\u636e\u5e93\u7684\u6570\u636e\u8868\u4e2d\uff0cMyCat\u7684\u5206\u7247\u89c4\u5219\u914d\u7f6e\u6587\u4ef6\u5728\uff1a<code>\/usr\/local\/mycat\/conf\/rule.xml<\/code>\u4e2d\uff0c\u76ee\u524d\u5e38\u7528\u7684\u5206\u7247\u89c4\u5219\u6709\uff1a<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6c42\u6a21\u5206\u5e93\uff1amod-long<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8303\u56f4\u5206\u5e93\uff1aauto-sharding-long<\/li><li>Hash\u5206\u5e93\uff1ahash-int<\/li><li>\u6708\u5206\u5e93\uff1asharding-by-month<\/li><li>ER\u6a21\u578b\u5206\u5e93\uff1achildTable<\/li><li>\u81ea\u5b9a\u4e49\u5206\u5e93\uff1aCustomRule(\u8be5\u65b9\u5f0f\u9700\u8981\u81ea\u5df1\u5b9e\u73b0\u5206\u5e93\u7b97\u6cd5)<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tableRule name=\"my-mod-long\">\n        &lt;rule>\n                &lt;columns>id&lt;\/columns>\n                &lt;algorithm>mod-long&lt;\/algorithm>\n        &lt;\/rule>\n&lt;\/tableRule>\n&lt;function name=\"my-mod-long\" class=\"io.mycat.route.function.PartitionByMod\">\n        &lt;property name=\"count\">3&lt;\/property>&lt;!--\u6c42\u6a21\u53d6\u4f59\u7684\u6570-->\n&lt;\/function>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\n<code>schema.xml<\/code>\u914d\u7f6e<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\">\n                &lt;table name=\"data\" primaryKey=\"id\" dataNode=\"dn1,dn2,dn3\" rule=\"my-mod-long\"\/>\n        &lt;\/schema>\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"db1\" \/>\n        &lt;dataNode name=\"dn2\" dataHost=\"localhost2\" database=\"db2\" \/>\n        &lt;dataNode name=\"dn3\" dataHost=\"localhost3\" database=\"db3\" \/>\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host1\" url=\"192.168.1.199:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost2\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host2\" url=\"192.168.1.166:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost3\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host3\" url=\"192.168.1.176:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\n<code>server.xml<\/code>\u914d\u7f6e<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;property name=\"schemas\">TESTDB&lt;\/property>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u542f\u52a8MyCat\u670d\u52a1<code>\/usr\/local\/mycat\/bin\/mycat console<\/code>\n<\/li><li>\u4f7f\u7528\u5ba2\u6237\u7aef\u7aef\u53e3\u8fdb\u884c\u8fde\u63a5<code>mysql -uroot -p123456 -h192.168.1.1 -P8066 -DTESTDB<\/code>\n<\/li><li>\u6b64\u65f6\uff0c\u5c31\u5b9e\u73b0\u4e86MyCat\u7684\u6c42\u6a21\u5206\u7247\uff0c\u6bcf\u5bf93\u8fdb\u884c\u53d6\u4f59\uff0c\u7136\u540e\u81ea\u52a8\u8fdb\u884c\u5206\u7247\u6570\u636e\u4fdd\u5b58\u5904\u7406<\/li><li>\u5e8f\u5217\u7684\u4f7f\u7528\uff1a<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5e8f\u5217\u7684\u914d\u7f6e\uff0c\u5728<code>usr\/local\/mycat\/conf\/sequence_conf.properties<\/code>\u6587\u4ef6\u4e2d<br\/>\u8fd8\u9700\u8981\u5728<code>server.xml<\/code>\u6587\u4ef6\u4e2d\u914d\u7f6e<br\/><code>&lt;property name=\"sequenceHandlerType\">0&lt;\/property><\/code><br\/>\u5728SQL\u4e2d\u4f7f\u7528<code>next value for MYCATSEQ_GLOBAL<\/code>\u8868\u793a\u5e8f\u5217\u589e\u957f<br\/><code>INSERT INTO data (id,title) VALUES (next value for MYCATSEQ_GLOBAL,@@hostname)<\/code>;<br\/><br\/><br\/>\u4f5c\u8005\uff1aiEvans<br\/>\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/26513f428ecf<br\/>\u4f86\u6e90\uff1a\u7b80\u4e66<br\/>\u7b80\u4e66\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\uff0c\u4efb\u4f55\u5f62\u5f0f\u7684\u8f6c\u8f7d\u90fd\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\u5e76\u6ce8\u660e\u51fa\u5904\u3002<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>\nB . \u8303\u56f4\u5206\u5e93\n<ul><li>\u8303\u56f4\u5206\u5e93\u6307\u7684\u662f\uff0c\u6839\u636eid\u7684\u8303\u56f4\u8fdb\u884c\u4e0d\u540c\u6570\u636e\u5e93\u7684\u4fdd\u5b58\uff0c\u6216\u8005\u6839\u636e\u6570\u636e\u5927\u5c0f\u7684\u4e0d\u540c\u6765\u8fdb\u884c\u4fdd\u5b58<\/li><li>\n<code>rule.xml<\/code>\u7684\u914d\u7f6e<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tableRule name=\"my-auto-sharding-long\">\n        &lt;rule>\n                &lt;columns>id&lt;\/columns>\n                &lt;algorithm>my-auto-sharding-long&lt;\/algorithm>\n        &lt;\/rule>\n&lt;\/tableRule>\n&lt;function name=\"my-auto-sharding-long\" class=\"io.mycat.route.function.AutoPartitionByLong\">\n        &lt;property name=\"mapFile\">partition-long.txt&lt;\/property>&lt;!--\u8303\u56f4\u89c4\u5219\u6587\u4ef6-->\n&lt;\/function>\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> - \u6b64\u65f6\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u8303\u56f4\u5206\u5e93\u7684\u89c4\u5219\u95ee\u6d25`partition-long.txt`\uff0c\u5e76\u5b58\u653e\u5728`conf`\u76ee\u5f55\u4e2d`vim \/usr\/local\/mycat\/conf\/partition-long.txt`\n - partition-long.txt\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u6839\u636e\u6570\u636e\u7f16\u53f7\u5212\u5206<br\/>\n0-10000=0<br\/>\n10001-20000=1<br\/>\n20001-30000=2<\/p><\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code> - \u4fee\u6539`schema.xml`\u5339\u914d\u65b0\u7684\u5206\u7247\u89c4\u5219\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;table name=\"data\" primaryKey=\"id\" dataNode=\"dn1,dn2,dn3\" rule=\"my-auto-sharding-long\"\/>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\nC . Hash\u5206\u5e93\n<ul><li>Hash\u5206\u5e93\u6307\u7684\u662f\u6839\u636e\u67d0\u4e2a\u5b57\u6bb5\u7684\u7684\u56fa\u5b9a\u5185\u5bb9\u8fdb\u884c\u5206\u7247\uff0c\u4f8b\u5982\uff1a\u6839\u636e\u7701\u4efd\u5206\u7247\uff0c\u6839\u636e\u57ce\u5e02\u5206\u7247,\u4e00\u822c\u8fdb\u884cHash\u5206\u7247\u5904\u7406\u7684\uff0c\u90fd\u8981\u6709\u4e00\u4e9b\u56fa\u5b9a\u7684\u503c\u8fdb\u884c\u5339\u914d<\/li><li>\n<code>rule.xml<\/code>\u914d\u7f6e<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tableRule name=\"my-by-intfile\">\n        &lt;rule>\n                &lt;columns>title&lt;\/columns>\n                &lt;algorithm>my-hash-int&lt;\/algorithm>\n        &lt;\/rule>\n&lt;\/tableRule>\n&lt;function name=\"my-hash-int\" class=\"io.mycat.route.function.PartitionByFileMap\">\n                &lt; property name=\"type\">1&lt;\/property>&lt;!--0\u8868\u793a\u6570\u5b57\u578b\u5206\u7247\uff0c1\u8868\u793a\u5b57\u7b26\u4e32\u5206\u7247-->\n        &lt;property name=\"mapFile\">partition-hash-int.txt&lt;\/property>&lt;!--Hash\u89c4\u5219\u6587\u4ef6-->\n&lt;\/function>\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>- `schema.xml`\u914d\u7f6e\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;table name=\"data\" primaryKey=\"title\" dataNode=\"dn1,dn2,dn3\" rule=\"my-by-intfile\"\/>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\nD . \u6309\u6708\u5206\u5e93\n<ul><li>\u6bcf\u4e2a\u6708\u5b58\u5165\u6bcf\u4e2a\u6708\u5355\u72ec\u7684\u6570\u636e\u5e93\u4e2d<\/li><li>\n<code>rule.xml<\/code>\u914d\u7f6e<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;tableRule name=\"my-by-month\">\n        &lt;rule>\n                &lt;columns>saledate&lt;\/columns>\n                &lt;algorithm>my-partbymonth&lt;\/algorithm>\n        &lt;\/rule>\n&lt;\/tableRule>\n&lt;function name=\"my-partbymonth\" class=\"io.mycat.route.function.PartitionByMonth\">\n                &lt; property name=\"dateFormat\">yyyy-MM-dd&lt;\/property>\n        &lt;property name=\"sBeginDate\">2017-01-01&lt;\/property>\n&lt;\/function>\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>- `schema.xml`\u914d\u7f6e\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\">\n                &lt;!--\u4f7f\u7528$\u8868\u793a\u901a\u914d\u7b26-->\n                &lt;table name=\"data\" primaryKey=\"id\" dataNode=\"dn$1-12\" rule=\"my-by-month\"\/>\n        &lt;\/schema>\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"db1\" \/>\n        &lt;dataNode name=\"dn2\" dataHost=\"localhost2\" database=\"db2\" \/>\n        &lt;dataNode name=\"dn3\" dataHost=\"localhost3\" database=\"db3\" \/>\n        &lt;dataNode name=\"dn4\" dataHost=\"localhost4\" database=\"db4\" \/>\n        &lt;dataNode name=\"dn5\" dataHost=\"localhost5\" database=\"db5\" \/>\n        &lt;dataNode name=\"dn6\" dataHost=\"localhost6\" database=\"db6\" \/>\n        &lt;dataNode name=\"dn7\" dataHost=\"localhost7\" database=\"db7\" \/>\n        &lt;dataNode name=\"dn8\" dataHost=\"localhost8\" database=\"db8\" \/>\n        &lt;dataNode name=\"dn9\" dataHost=\"localhost9\" database=\"db9\" \/>\n        &lt;dataNode name=\"dn10\" dataHost=\"localhost10\" database=\"db10\" \/>\n        &lt;dataNode name=\"dn11\" dataHost=\"localhost11\" database=\"db11\" \/>\n        &lt;dataNode name=\"dn12\" dataHost=\"localhost12\" database=\"db12\" \/>\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host1\" url=\"192.168.1.166:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost2\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host2\" url=\"192.168.1.199:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost3\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host3\" url=\"192.168.1.116:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost4\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host4\" url=\"192.168.1.150:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost5\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host5\" url=\"192.168.1.152:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost6\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host6\" url=\"192.168.1.177:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost7\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host7\" url=\"192.168.1.136:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost8\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host8\" url=\"192.168.1.153:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost9\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host9\" url=\"192.168.1.159:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost10\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host10\" url=\"192.168.1.176:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost11\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host11\" url=\"192.168.1.156:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost12\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host12\" url=\"192.168.1.136:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\nE . ER\u6a21\u578b\u5206\u5e93\n<ul><li>\u6839\u636e\u6570\u636e\u5e93\u7684ER\u6a21\u578b\u8fdb\u884c\u5206\u5e93\uff0c\u5373\u8fdb\u884c\u591a\u8868\u5173\u8054\u5206\u5e93\u7ba1\u7406<\/li><li>\n<code>schema.xml<\/code>\u914d\u7f6e<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE mycat:schema SYSTEM \"schema.dtd\">\n&lt;mycat:schema xmlns:mycat=\"http:\/\/io.mycat\/\">\n        &lt;schema name=\"TESTDB\" checkSQLschema=\"false\" sqlMaxLimit=\"100\">\n                &lt;!--\u6b64\u5904\u8868\u793a\u7236\u8868\u4e0e\u5b50\u8868\u7684\u76f8\u4e92\u5173\u8054-->\n                &lt;table name=\"data\" primaryKey=\"id\" dataNode=\"dn$1-3\" rule=\"my-mod-long\">\n                        &lt;childTable name=\"data_details\" joinKey=\"id\" primaryKey=\"ddid\" parentKey=\"id\"\/>\n                &lt;\/table>\n        &lt;\/schema>\n        &lt;dataNode name=\"dn1\" dataHost=\"localhost1\" database=\"db1\" \/>\n        &lt;dataNode name=\"dn2\" dataHost=\"localhost2\" database=\"db2\" \/>\n        &lt;dataNode name=\"dn3\" dataHost=\"localhost3\" database=\"db3\" \/>\n        &lt;dataHost name=\"localhost1\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host1\" url=\"192.168.122.166:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost2\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host2\" url=\"192.168.122.199:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n        &lt;dataHost name=\"localhost3\" maxCon=\"1000\" minCon=\"10\" balance=\"2\"\n                          writeType=\"0\" dbType=\"mysql\" dbDriver=\"native\" switchType=\"1\"  slaveThreshold=\"100\">\n                &lt;heartbeat>select user()&lt;\/heartbeat>\n                &lt;writeHost host=\"host3\" url=\"192.168.122.198:3306\" user=\"root\" password=\"123456\"\/>\n        &lt;\/dataHost>\n&lt;\/mycat:schema>\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\nF . \u81ea\u5b9a\u4e49\u5206\u5e93\u89c4\u5219\n<ul><li>\u5206\u5e03\u5f0f\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff0c\u5206\u7247\u89c4\u5219\u7528\u4e8e\u5b9a\u4e49\u6570\u636e\u4e0e\u5206\u7247\u7684\u8def\u7531\u5173\u7cfb\uff0c\u4e5f\u5c31\u662f insert\uff0cdelete\uff0cupdate\uff0cselect \u7684\u57fa\u672c sql \u64cd\u4f5c\u4e2d\uff0c\u5982\u4f55\u5c06 sql \u8def\u7531\u5230\u5bf9\u5e94\u7684\u5206\u7247\u6267\u884c\u3002<br\/>\nMycat \u7684\u603b\u4f53\u8def\u7531\u56fe\u4e3a:<\/li><\/ul>\n<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>&#8211; \u5b98\u65b9\u6848\u4f8b\u5206\u6790\uff1a<\/p><\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><\/blockquote>\n\n\n\n<p>\u4f5c\u8005\uff1aiEvans<br\/>\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/26513f428ecf<br\/>\u4f86\u6e90\uff1a\u7b80\u4e66<br\/>\u7b80\u4e66\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\uff0c\u4efb\u4f55\u5f62\u5f0f\u7684\u8f6c\u8f7d\u90fd\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\u5e76\u6ce8\u660e\u51fa\u5904\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u914d\u7f6e 1 . \u5728mycat\/conf\u76ee\u5f55\u4e0b\uff0cMyCat\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\uff1aschema.xml 2 . dataHost\u6807\u7b7e\u4e0a\u5c5e\u6027\u91ca\u4e49\uff1a balance:\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b 0\uff1a\u4e0d\u5f00\u542f\u8bfb\u5199\u5206\u79bb\u673a\u5236\uff0c\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u53d1\u9001\u5230\u5f53\u524d\u53ef\u7528\u7684writeHost\u4e0a 1\uff1a\u5168\u90e8\u7684readHost\u4e0estand by writeHost\u53c2\u4e0eselect\u8bed\u53e5\u7684\u8d1f\u8f7d\u5747\u8861\uff0c 2\uff1a\u6240\u6709\u8bfb\u64cd\u4f5c\u90fd\u968f\u673a\u5728writeHost\u3001readHost\u4e0a\u5206\u53d1 3\uff1a\u6240\u6709\u8bfb\u8bf7\u6c42\u968f\u673a\u5206\u53d1\u5230writeHost\u5bf9\u5e94\u7684readHost\u6267\u884c\uff0cwriteHost\u4e0d\u8d1f\u62c5\u8bfb\u538b\u529b writeType:\u8d1f\u8f7d\u5747\u8861\u7c7b\u578b 0\uff1a\u6240\u6709\u5199\u64cd\u4f5c\u53d1\u9001\u5230\u914d\u7f6e\u7684\u7b2c\u4e00\u4e2awriteHost\uff0c\u5f53\u7b2c\u4e00\u4e2awriteHost\u5b95\u673a\u65f6\uff0c\u5207\u6362\u5230\u7b2c\u4e8c\u4e2awriteHost\uff0c\u91cd\u65b0\u542f\u52a8\u540e\u4ee5\u5207\u6362\u540e\u7684\u4e3a\u51c6\uff0c\u5207\u6362\u8bb0\u5f55\u5728\u914d\u7f6e\u6587\u4ef6\uff1adnindex.properties\u4e2d 1\uff1a\u6240\u6709\u5199\u64cd\u4f5c\u90fd\u968f\u53d1\u9001\u5230\u914d\u7f6e\u7684writeHost 2\uff1a\u5c1a\u672a\u5b9e\u73b0 switchType:\u5207\u6362\u65b9\u5f0f -1\uff1a\u4e0d\u81ea\u52a8\u5207\u6362 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-944","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/944","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=944"}],"version-history":[{"count":0,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=\/wp\/v2\/posts\/944\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=944"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=944"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.jsjs.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=944"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}