ip | 角色 | 端口 |
---|---|---|
128.0.0.101 | master | 3306 |
128.0.0.102 | slave | 3306 |
128.0.0.103 | mycat | 8066 |
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">
<schema name="alex_schema1" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema>
<schema name="alex_schema2" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn2"></schema>
<dataNode name="dn1" dataHost="localhost1" database="alex" />
<dataNode name="dn2" dataHost="localhost1" database="alex11" />
<dataHost name="localhost1" maxCon="500" minCon="20" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="2" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="hostM1" url="128.0.0.101:3306" user="root"
password="123456" />
<writeHost host="hostS1" url="128.0.0.102:3306" user="root"
password="123456" />
</dataHost>
</mycat:schema>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://org.opencloudb/">
<system>
<property name="defaultSqlParser">druidparser</property>
<property name="charset">utf8mb4</property>
</system>
<user name="user2">
<property name="password">password</property>
<property name="schemas">alex_schema1,alex_schema2</property>
</user>
<!-- 用户3,只读权限-->
<user name="user3">
<property name="password">password</property>
<property name="schemas">alex_schema1,alex_schema2</property>
<property name="readOnly">true</property>
</user>
</mycat:server>
mycat start
mysql -uuser2 -password -h128.0.0.103 -P8066
02/11 13:50:15.573 DEBUG [$_NIOREACTOR-0-RW] (PhysicalDBPool.java:431) -select read source hostS1 for dataHost:localhost1
#看到是conghosts1上面读写的说明是slave节点
02/11 13:57:37.387 DEBUG [$_NIOREACTOR-0-RW] (NonBlockingSession.java:230) -release connection MySQLConnection [id=1, lastTime=1518328657366, schema=alex11, old shema=alex11, borrowed=true, fromSlaveDB=false, threadId=63, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{INSERT INTO `alex11`.`ee` (`ss`, `aa`) VALUES ('哈哈哈ha', '111111')}, respHandler=SingleNodeHandler [node=dn2{INSERT INTO `alex11`.`ee` (`ss`, `aa`) VALUES ('哈哈哈ha', '111111')}, packetId=0], host=128.0.0.101, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
#看到是从host=128.0.0.101上面写入的说明是master节点