mycat2.0配置读写分离

执行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{} */;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值