1. {
  2. "dbType": "mysql",
  3. "idleTimeout": 60000,
  4. "initSqls": [],
  5. "initSqlsGetConnection": true,
  6. "instanceType": "READ_WRITE",
  7. "maxCon": 1000,
  8. "maxConnectTimeout": 3000,
  9. "maxRetryCount": 5,
  10. "minCon": 1,
  11. "name": "prototype",
  12. "password": "123456",
  13. "type": "JDBC",
  14. "url": "jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&serverTimezone=UTC",
  15. "user": "root",
  16. "weight": 0,
  17. "queryTimeout":30,//mills
  18. }

“jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&serverTimezone=UTC”
此处mysql要改成业务库,业务库不能被binlog等忽略

prototype.datasource.json
{数据源名字}.datasource.json 保存在datasources文件夹

maxConnectTimeout

单位millis,配置中的定时器主要作用是定时检查闲置连接

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
可选值

  1. READ_WRITE,READ,WRITE

在集群中,是READ_WRITE的类型,被设置到replicas,对该集群是READ的,但是它也被设置到masters则为READ_WRITE

这个属性要配合集群的负载均衡使用
FR88$~AC}FFIXD`2~6NCN8P.png
readBalanceType

weight
负载均衡特定用的权重

连接泄露检查(2022-5-9后)

  1. "removeAbandoned":true,//开启连接泄露检查,建议开启debug级别日志
  2. "removeAbandonedTimeoutSecond"180,//秒
  3. "logAbandoned": true//输出关闭连接的日志

如果jdbc是mysql官网驱动的话
url添加以下参数控制超时

  1. nettimeoutforstreamingresults来影响SET net_write_timeout = 600控制socket连接超时
  2. socketTimeout
  3. connectTimeout
  4. 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

  1. mysql设置上设置变量
  2. net_read_timeout
  3. net_write_timeout

设置MySQL JDBC数据源的网络缓冲区

  1. 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 |
  1. 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中的数据源设置,仅仅以下参数生效

  1. VertxPoolConnectionImpl.Config config = new VertxPoolConnectionImpl.Config();
  2. config.setHost(host);//jdbc的url获取的
  3. config.setPassword(password);
  4. config.setUsername(username);
  5. config.setPort(port);//jdbc的url获取的
  6. config.setDatabase(connectionUrlParser.getPath());//jdbc的url获取的
  7. config.setRetry(datasource.getMaxRetryCount());//连接重视次数
  8. 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

  1. {
  2. "dbType": "mysql",
  3. "idleTimeout": 60000,
  4. "initSqls": [],
  5. "initSqlsGetConnection": true,
  6. "instanceType": "READ_WRITE",
  7. "maxCon": 1000,
  8. "maxConnectTimeout": 3000,
  9. "maxRetryCount": 5,
  10. "minCon": 1,
  11. "name": "mongodb",
  12. "password": "123456",
  13. "type": "JDBC",
  14. "url": "mongodb://192.168.0.99/test",
  15. "user": "root",
  16. "weight": 0,
  17. "queryTimeout":30,//mills
  18. }

供参考的驱动版本

  1. <dependency>
  2. <groupId>org.mongodb</groupId>
  3. <artifactId>mongo-java-driver</artifactId>
  4. <version>3.12.10</version>
  5. </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>