http://www.blogjava.net/amigoxie/archive/2014/12/24/421788.html
上面的链接很详细,下面是小结
解压Mycat-server-1.5-RELEASE-20160301083012-win.tar
安装步骤:
启动前,一般需要修改JVM配置参数,打开conf/wrapper.conf文件,如下行的内容为2G和2048,可根据本机配置情况修改为512M或其它值。
wrapper.java.additional.5=-XX:MaxDirectMemorySize=512M
wrapper.java.additional.6=-Dcom.sun.management.jmxremote
wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984
wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false
wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false
# Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3
wrapper.java.initmemory=512
# Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64
wrapper.java.maxmemory=512
在命令行窗口中进入MyCAT安装解压文件下的bin目录,输入如下命令可安装(可选)、启动和停止MyCAT,参考结果如下所示:
D:\software\Mycat-server-1.2-GA-win\bin>mycat install
wrapper | Mycat-server installed.
D:\software\Mycat-server-1.2-GA-win\bin>mycat start
wrapper | Starting the Mycat-server service
wrapper | Waiting to start
wrapper | Mycat-server started.
D:\software\Mycat-server-1.2-GA-win\bin>mycat stop
wrapper | Stopping the Mycat-server service
wrapper | Mycat-server stopped.
垂直分切
<schema name="weixin" checkSQLschema="false" sqlMaxLimit="100" dataNode="weixin" />
<schema name="yixin" checkSQLschema="false" sqlMaxLimit="100" dataNode="yixin" />
<schema name="photo" checkSQLschema="false" sqlMaxLimit="100" dataNode="photo" />
<schema name="bbb" checkSQLschema="false" sqlMaxLimit="100" dataNode="bbb" />
<dataNode name="weixin" dataHost="testhost" database="weixin" />
<dataNode name="yixin" dataHost="testhost" database="yixin" />
<dataNode name="photo" dataHost="testhost" database="photo" />
<dataNode name="bbb" dataHost="testhost2" database="bbb" />
<!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
<dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
<dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
<dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> -->
<dataHost name="testhost" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root" password="123456" />
</dataHost>
<dataHost name="testhost2" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM2" url="localhost:3307" user="root" password="123456" />
</dataHost>
水平分表
http://wenku.baidu.com/view/78abcf392b160b4e777fcf6c.html?qq-pf-to=pcqq.c2c
配置文件:schema.xml
自定义一个虚拟数据库mycat 里面添加要水平分表的userinfo(这个表在weixin,bbb的两个数据库中都存在,表结构一样)
<schema name="mycat" checkSQLschema="false" sqlMaxLimit="100" >
<!-- auto sharding by id (long) -->
<table name="userinfo" primaryKey="UPID" dataNode="weixin,bbb" rule="rule1">
</table>
</schema>
配置文件:rule.xml
下面partitionCount是要分库的数量,partitionLength是当多少条数据的时候进行分片,大概意思就是这样。
<tableRule name="rule1">
<rule>
<columns>UPID</columns>
<algorithm>func1</algorithm>
</rule>
</tableRule>
<function name="func1" class="org.opencloudb.route.function.PartitionByLong">
<property name="partitionCount">2</property>
<property name="partitionLength">512</property>
</function>
--------------------------------
还可以这样写
<function name="func1" class="org.opencloudb.route.function.PartitionByLong">
<property name="partitionCount">1,1</property>
<property name="partitionLength">512,512</property>
</function>
配置文件:server.xml
最后不要忘记配置数据库
<user name="test">
<property name="password">test</property>
<property name="schemas">weixin,yixin,photo,bbb,mycat</property>
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">weixin,yixin,photo,bbb,mycat</property>
<property name="readOnly">true</property>
</user>
最后项目里链接数据库字符串需要链接这个带有分表的库mycat
读写分离:
<dataHost name="testhost" maxCon="1000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="localhost:3306" user="root" password="">
<readHost host="hostM2" url="10.18.96.133:3306" user="test" password="test" />
</writeHost>
</dataHost>
全局表:
<schema name="test_mycat" checkSQLschema="false" sqlMaxLimit="100">
<!-- auto sharding by id (long) -->
<table name="t_user" dataNode="user0,user1,user2,user3" rule="rule1">
<childTable name="t_user_class_rel" primaryKey="id" joinKey="user_id" parentKey="user_id" />
</table>
<table name="t_area" primaryKey="id" type="global" dataNode="weixin,yixin,photo,user0,user1,user2,user3" />
</schema>
查看端口是否被占用:netstat -ano
.NET 链接 MySQL
所需DLL:MySQL.Data (可借助动软代码生成器生成的项目中找到)。
所需数据库访问类:DbHelperMySQL(可从动软代码生成器的项目中找到)。
WebConfig 中链接数据库字符串:
<connectionStrings><addname="sql_conn" connectionString="server=localhost;port=3306;database=weixin;uid=root;pwd=123456;"/></connectionStrings>
利用SQLBase泛型底层 (注意添加时表名不能加中括号“[ ]”,还有一些sql语句和mysql不太一样自己探索把)。
利用SmileAngel dapper通用底层可以实现你想要的及你想不到的.................