{
"dbType": "mysql",
"idleTimeout": 60000,
"initSqls": [],
"initSqlsGetConnection": true,
"instanceType": "READ_WRITE",
"maxCon": 1000,
"maxConnectTimeout": 3000,
"maxRetryCount": 5,
"minCon": 1,
"name": "prototype",
"password": "123456",
"type": "JDBC",
"url": "jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&serverTimezone=UTC",
"user": "root",
"weight": 0,
"queryTimeout":30,//mills
}
“jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&serverTimezone=UTC”
此处mysql要改成业务库,业务库不能被binlog等忽略
prototype.datasource.json
{数据源名字}.datasource.json 保存在datasources文件夹
maxConnectTimeout
initSqlsGetConnection
true|false,默认:false,对于jdbc每次获取连接是否都执行initSqls
type
数据源类型
JDBC,默认,只使用JDBC驱动连接
NATIVE_JDBC,该数据源同一个配置同时可以使用NATIVE,JDBC
NATIVE,只使用NATIVE协议(即Mycat自研的连接MySQL的协议)
没有必要不要使用NATIVE
queryTimeout
jdbc查询超时时间 默认不超时(1.20,以及早期1.21默认30mills)
JDBC禁用SSL属性有助提高性能
instanceType配置实例只读还是读写,读节点可以设置为READ
可选值
READ_WRITE,READ,WRITE
在集群中,是READ_WRITE的类型,被设置到replicas,对该集群是READ的,但是它也被设置到masters则为READ_WRITE
这个属性要配合集群的负载均衡使用
readBalanceType
weight
负载均衡特定用的权重
连接泄露检查(2022-5-9后)
"removeAbandoned":true,//开启连接泄露检查,建议开启debug级别日志
"removeAbandonedTimeoutSecond"180,//秒
"logAbandoned": true//输出关闭连接的日志
如果jdbc是mysql官网驱动的话
url添加以下参数控制超时
nettimeoutforstreamingresults来影响SET net_write_timeout = 600控制socket连接超时
socketTimeout
connectTimeout
jdbc:mysql://xxx:3306/mysql?useUnicode=true&characterEncoding=UTF8&nettimeoutforstreamingresults=600
0000-00-00 00:00:00问题
Caused by: com.mysql.cj.exceptions.DataReadException: Zero date value prohibited
jdbc字符串添加zeroDateTimeBehavior=convertToNull
mysql设置上设置变量
net_read_timeout
net_write_timeout
设置MySQL JDBC数据源的网络缓冲区
jdbc:mysql://xxx:3306/mysql?tcpRcvBufIf=0
tcpRcvBufIf=0
- tcpRcvBufIf connecting using TCP/IP, should the driver set SO_RCV_BUF to the given value? The default value of ‘0’, means use the platform default value for this property) | Default Value | 0 | | —- | —- | | Since Version | 5.0.7 |
jdbc:mysql://xxx:3306/mysql?tcpSndBufIf=0
tcpSndBufIf=0
- tcpSndBufIf connecting using TCP/IP, should the driver set SO_SND_BUF to the given value? The default value of ‘0’, means use the platform default value for this property) | Default Value | 0 | | —- | —- | | Since Version | 5.0.7 |
https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-connp-props-networking.html#cj-conn-prop_tcpRcvBuf
native数据源(v1.22)
使用native数据源需要注意以下问题,不建议使用blob值,不建议使用带有一定闲置时间的业务场景,网络环境不佳的环境也不要使用,只支持native_password插件登录授权
对于mycat中的数据源设置,仅仅以下参数生效
VertxPoolConnectionImpl.Config config = new VertxPoolConnectionImpl.Config();
config.setHost(host);//jdbc的url获取的
config.setPassword(password);
config.setUsername(username);
config.setPort(port);//jdbc的url获取的
config.setDatabase(connectionUrlParser.getPath());//jdbc的url获取的
config.setRetry(datasource.getMaxRetryCount());//连接重视次数
config.setTimer(datasource.getIdleTimeout());//闲置连接检查时间,毫秒
native数据源支持连接实现了mysql网络协议的数据库,比如Apache Drois,Clickhouse。当然直接用jdbc的mysql驱动也可以连接它们.但是它们可能在sql语法上有些细节与mysql不同,这是需要注意的,需要相关技术支持请联系Mycat团队。
nosql支持(v1.21-2021-10-25)
nosql数据源不能配置为原型库,而且不支持集群和心跳
该功能移植自mycat1.6 只支持简单sql计算下推计算,但是可以与其他数据源进行联邦查询
是用该功能需要自行引入驱动jar,放在mycat的jar同一个文件夹内
mongodb
{
"dbType": "mysql",
"idleTimeout": 60000,
"initSqls": [],
"initSqlsGetConnection": true,
"instanceType": "READ_WRITE",
"maxCon": 1000,
"maxConnectTimeout": 3000,
"maxRetryCount": 5,
"minCon": 1,
"name": "mongodb",
"password": "123456",
"type": "JDBC",
"url": "mongodb://192.168.0.99/test",
"user": "root",
"weight": 0,
"queryTimeout":30,//mills
}
供参考的驱动版本
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.10</version>
</dependency>
sequoiadb
{
"dbType": "mysql",
"idleTimeout": 60000,
"initSqls": [],
"initSqlsGetConnection": true,
"instanceType": "READ_WRITE",
"maxCon": 1000,
"maxConnectTimeout": 3000,
"maxRetryCount": 5,
"minCon": 1,
"name": "sequoiadb",
"password": "123456",
"type": "JDBC",
"url": "sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE",
"user": "root",
"weight": 0,
"queryTimeout":30,//mills
}
供参考的驱动版本
<dependency>
<groupId>com.sequoiadb</groupId>
<artifactId>sequoiadb-driver</artifactId>
<version>5.0.2</version>
</dependency>