MyCAT2的主从配置
1.创建数据源
重置配置:/*+ mycat:resetConfig{} */
添加读写的数据源
/*+ mycat:createDataSource
{
"dbType": "mysql",
"idleTimeout": 60000,
"initSqls": [],
"initSqlsGetConnection": true,
"instanceType": "READ_WRITE",
"maxCon": 1000,
"maxConnectTimeout": 3000,
"maxRetryCount": 5,
"minCon": 1,
"name": "yyy",
"password": "root@123",
"type": "JDBC",
"url": "jdbc:mysql://192.168.8.100:3306?useUnicode=true&serverTimezone=UTC&characterEncoding=UTF-8",
"user": "root",
"weight": 0
}
*/
-- 更多操作添加读的数据源
/*+ mycat:createDataSource
{
"dbType": "mysql",
"idleTimeout": 60000,
"initSqls": [],
"initSqlsGetConnection": true,
"instanceType": "READ",
"maxCon": 1000,
"maxConnectTimeout": 3000,
"maxRetryCount": 5,
"minCon": 1,
"name": "yyyy",
"password": "root@123",
"type": "JDBC",
"url": "jdbc:mysql://192.168.8.101:3306?useUnicode=true&serverTimezone=UTC&characterEncoding=UTF-8",
"user": "root",
"weight": 0
}
*/
2.查询数据源:/*+ mycat:showDataSources{} */
3.创建集群
/*+ mycat:createCluster{
"clusterType":"MASTER_SLAVE",
"heartbeat":{
"heartbeatTimeout":1000,
"maxRetry":3,
"minSwitchTimeInterval":300,
"slaveThreshold":0
},
"masters":[ "yyy" ],
"maxCon":2000,
"name":"prototype",
"readBalanceType":"BALANCE_ALL",
"replicas":[ "yyyy" ],
"switchType":"SWITCH"
} */;