系统存在2个Mariadb 10.3数据库主从集群
数据库 | master | slave | 用户名 | 密码 |
---|---|---|---|---|
mall | 192.168.1.100 | 192.168.1.110 | root | 123456 |
member | 192.168.1.150 | 192.168.1.160 | root | 123456 |
schema.xml文件如下:
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="mall" checkSQLschema="false" sqlMaxLimit="100" dataNode="mall_dn" >
</schema>
<schema name="member" checkSQLschema="false" sqlMaxLimit="100" dataNode="member_dn" >
</schema>
<dataNode name="mall_dn" dataHost="malldbhost" database="mall" />
<dataNode name="member_dn" dataHost="memberdbhost" database="member" />
<dataHost name="malldbhost" maxCon="1000" minCon="10" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="master" url="192.168.1.100:3306" user="root" password="123456">
<readHost host="slave" url="192.168.1.110:3306" user="root" password="123456">
</readHost>
</writeHost>
</dataHost>
<dataHost name="memberdbhost" maxCon="1000" minCon="10" balance="3"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="membermaster" url="192.168.1.150:3306" user="root" password="123456">
<readHost host="memberslave" url="192.168.1.160:3306" user="root" password="123456">
</readHost>
</writeHost>
</dataHost>
</mycat:schema>
server.xml局部
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">mall,member</property>
</user>
<user name="mall" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">mall</property>
</user>
<user name="member" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">member</property>
</user>
<user name="read">
<property name="password">123456</property>
<property name="schemas">mall,member</property>
<property name="readOnly">true</property>
</user>
来源:51CTO
作者:rong341233
链接:https://blog.51cto.com/fengwan/2461350