分库分表,在本节里是水平切分,就是多个数据库里包含的表是一模一样的。
只是把字段散列的分到不同的库中。
实践: 1.修改schema.xml这里是在同一台服务器上建立了4个数据库db1,db2,db3,db4
1 <?xml version="1.0"?> 2 <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> 3 <mycat:schema xmlns:mycat="http://io.mycat/"> 4 5 <!-- 配置逻辑库XMDB --> 6 <schema name="XMDB" checkSQLschema="false" sqlMaxLimit="100"> 7 <table name="user" dataNode="dn1,dn2,dn3,dn4" rule="crc32slot"/> 8 </schema> 9 <dataNode name="dn1" dataHost="node1" database="db1"/> 10 <dataNode name="dn2" dataHost="node1" database="db2"/> 11 <dataNode name="dn3" dataHost="node1" database="db3"/> 12 <dataNode name="dn4" dataHost="node1" database="db4"/> 13 <dataHost name="node1" maxCon="1000" minCon="10" balance="1" dbType="mysql" dbDriver="native"> 14 <heartbeat>select user()</heartbeat> 15 <writeHost host="192.168.40.3" url="192.168.40.3:3306" user="root" password="123456"> 16 <readHost host="192.168.40.3" url="192.168.40.3:3316" user="root" password="123456" /> 17 </writeHost> 18 </dataHost> 19 20 21 <!-- 22 <dataHost maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc"> 23 <heartbeat> </heartbeat> 24 <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng" password="jifeng"></writeHost> 25 </dataHost> 26 27 <dataHost maxCon="1000" minCon="1" balance="0" writeType="0" dbType="oracle" dbDriver="jdbc"> <heartbeat>select 1 from dual</heartbeat> 28 <connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql> 29 <writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base" password="123456" > </writeHost> </dataHost> 30 31 <dataHost maxCon="1000" minCon="1" balance="0" writeType="0" dbType="mongodb" dbDriver="jdbc"> 32 <heartbeat>select user()</heartbeat> 33 <writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost> </dataHost> 34 35 <dataHost maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc"> 36 <heartbeat> </heartbeat> 37 <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng" password="jifeng"></writeHost> </dataHost> --> 38 39 <!-- <dataHost maxCon="1000" minCon="10" balance="0" dbType="mysql" 40 dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" 41 url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost> 42 </dataHost> --> 43 </mycat:schema>