mycat多逻辑库配置文件
schema.xml文件配置
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <!--第一个逻辑库 --> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"> </schema> <!--第二个逻辑库 --> <schema name="TESTDB1" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn2"> </schema> <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743" /> --> <!--第一个库指定 --> <dataNode name="dn1" dataHost="localhost1" database="wordpress" /> <!--第二个库指定 --> <dataNode name="dn2" dataHost="localhost2" database="powerdns" /> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="2" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <!--第一个库指定数据库连接配置 --> <writeHost host="hostM1" url="10.0.0.88:3306" user="wordpress" password="123456"> <!-- can have multi read hosts --> <readHost host="hostS2" url="10.0.0.98:3306" user="wordpress" password="123456" /> </writeHost> </dataHost> <!--第二个库指定数据库连接配置 --> <dataHost name="localhost2" maxCon="1000" minCon="10" balance="2" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <!-- can have multi write hosts --> <writeHost host="hostM2" url="10.0.0.88:3306" user="powerdns" password="123456"> <!-- can have multi read hosts --> <readHost host="hostS2" url="10.0.0.98:3306" user="powerdns" password="123456" /> </writeHost> </dataHost> </mycat:schema>
要实现多逻辑库且映射到后端库,须在server.xml配置文件中更改以下选项
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">TESTDB,TESTDB1</property> #修改此行,将需要映射的库加入此行,用逗号隔开
<property name="defaultSchema">TESTDB</property>
<!--No MyCAT Database selected 错误前会尝试使用该schema作为schema,不设置则为null,报错 -->