执行mysql -uroot -p123456 -h172.17.0.1 -P8066 进入mycat的交互界面:
1、配置数据源:
/*+ mycat:createDataSource{
"name":"two",
"url":"jdbc:mysql://172.17.0.3:3306",
"user":"root",
"password":"123456"
} */;
mycat/conf/datasources就会多出一个文件:two.datasource.json
{
"dbType":"mysql",
"idleTimeout":60000,
"initSqls":[],
"initSqlsGetConnection":true,
"instanceType":"READ_WRITE",
"maxCon":1000,
"maxConnectTimeout":30000,
"maxRetryCount":5,
"minCon":1,
"name":"two",
"password":"123456",
"queryTimeout":30,
"type":"JDBC",
"url":"jdbc:mysql://172.17.0.3:3306?useUnicode=true&serverTimezone=Asia/Shanghai&characterEncoding=UTF-8&autoReconnect=true",
"user":"root",
"weight":0
}
2、配置集群:
/*! mycat:createCluster{"name":"prototype","masters":["prototypeDs"],"replicas":["two"]} */;
/opt/mycat/mycat/conf/clusters 下的prototype.cluster.json中的数据会被修改
{
"clusterType":"MASTER_SLAVE",
"heartbeat":{
"heartbeatTimeout":1000,
"maxRetryCount":3,
"minSwitchTimeInterval":300,
"slaveThreshold":0.0
},
"masters":[
"prototypeDs"
],
"maxCon":2000,
"name":"prototype",
"readBalanceType":"BALANCE_ALL",
"replicas":[
"two"
],
"switchType":"SWITCH"
}
3、查看集群状态
/*+ mycat:showClusters{} */;