1.下载
# wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
2.安装
# tar -zxvf ~/Mycat-server-1.6-RELEASE--linux.tar.gz -C /usr/local
3.配置schema.xml
# cd /usr/local/mycat/conf
# vim schema.xml
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!--schema 数据库-->
<schema name="testMyCat" checkSQLschema="false" sqlMaxLimit="100">
<!--table 表名-->
<table name="order" type="global" dataNode="order" />
<table name="orderDetail" type="global" dataNode="orderDetail" />
<table name="commodity" type="global" dataNode="order" />
</schema>
<!---datanode数据节点,database对应各个datahost中的数据库名,datahost用于配置数据库服务器地址->
<dataNode name="order" dataHost="host2" database="jxtest" />
<dataNode name="orderDetail" dataHost="host1" database="usercenter" />
<dataHost name="host1" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM1" url="192.168.3.30:3306" user="root" password="Gaia@Works12345^&*()" />
</dataHost>
<dataHost name="host2" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM2" url="192.168.3.62:4000" user="root" password="" />
</dataHost>
</mycat:schema>
mycat就是把跨库的数据库表,汇集到schema(新库)中,然后就可以join查询了
4.配置server.xml
# vim server.xml #然后找到user节点配置
<user name="root">
<property name="password">123456</property>
<property name="schemas">testMyCat</property>
</user>
<!--user.name登陆用户名,password登录密码,schemas该用户可使用的数据库名,testMayCat对应schema.xml文件中配置的schema-->
5.启动mycat
# cd /usr/local/mycat/bin
# ./mycat start
6.查看mycat状态
# ./mycat status
Mycat-server is running ().
7.使用mysql客户端连接mycat
然后就可以使用mysql语法查询了
8. 两个表的join
/*!mycat:catlet=io.mycat.catlets.ShareJoin */
SELECT
*
FROM t_order t
INNER JOIN order_detail td ON t.orderId = td.orderId
9.三个表的join
/*!mycat:catlet=io.mycat.catlets.ShareJoin */
SELECT
*
FROM t_order t
INNER JOIN order_detail td ON t.orderId = td.orderId
INNER JOIN commodity c ON td.commodityId = c.id
可见,三个表的join,mycat是不支持的