Mycat学习手册--15常见错误

常见错误

1.PacketTooBigException

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (44 > -1). You can change this value on the server by setting the max_allowed_packet’ variable。
原因
将版本更换为5.1.35后不报错
官网上
MycatJDBC连接报 PacketTooBigException异常
答:检查mysqljdbc驱动的版本,在使用mycat1.3和mycat1.4版本情况下,不要使用jdbc5.1.37和38版本的驱动,会出现如下异常报错:com.mysql.jdbc.PacketTooBigException: Packet for query is too large (60 > -1). You can change this value on the server by setting the max_allowed_packet’ variable。建议使用jdbc5.1.35或者36的版本。
mycat1.6同样会出现这个问题,换成mysql5.1.40同样可用

2.错误 ConfigException

Caused by: io.mycat.config.util.ConfigException: java.lang.NullPointerException
原因
schema.xml配置文件错误,我的dataNode上下不匹配了。

3.Timed out

Startup failed: Timed out waiting for a signal from the JVM.
JVM did not exit on request, terminated
解决办法
在wrapper.conf中添加

#超时时间300秒
wrapper.startup.timeout=300 
wrapper.ping.timeout=120

通过startup_nowrap.sh启动,报错
Caused by: io.mycat.config.util.ConfigException: Illegal table conf : table [ …] rule function [ rang-long ] partition size : 3 > table datanode size : 2, please make sure table datanode size = function partition size
默认的分片是分为3片,而我就设置了2个库。然后我又填了个新库,可以正常启动。
如果要修改分片规则,则需要修改rule.xml和其中对应的规则文件。

4.NumberFormatException

MyCATSequenceProcessor.executeSeq(SesionSQLPair) java.lang.NumberFormatException: null
原因,主键编号未获取到
<property name="sequnceHandlerType">0</property>本地文件方式
sequence_conf.properties文件未配置表名

#default global sequence
GLOBAL.HISIDS=
GLOBAL.MINID=1
GLOBAL.MAXID=20000000
GLOBAL.CURID=0

# self define sequence
COMPANY.HISIDS=
COMPANY.MINID=1
COMPANY.MAXID=2000000
COMPANY.CURID=410

<table name="tbl" primaryKey="ID" autoIncrement="true" dataNode="dn$0-11" rule="sharding-by-substring" />

COMPANY应为schema.xml中的表名对应的大写,此处应为TBL

5.SQLSyntaxErrorException

java.sql.SQLSyntaxErrorException: com.alibaba.druid.sql.parser.ParserException: syntax error, expect ‘)’
原因
报SQL语法错误,应该是SQL语句中有内嵌函数。
我的INSERT语句中VALUES中有时间函数now()

6.SQLNonTransientException

SELECT aaa a, bbb b, ccc c, status status FROM demo WHERE a = ‘11111’ AND b = ‘22222’ AND status=1 err:java.sql.SQLNonTransientException: can’t find table define in schema STATUS schema:demo
原因
status字段名和别名一样,导致解析错误,去掉别名或者改成其他别名后正常

7.错误,按月分片

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Can’t find a valid data node for specified node index :TESTDB -> CREATE_TIME -> 2017-07-11 16:38:49 -> Index : 30
按自然月分片(sharding-by-month),rule.xml中function中设置为

<function name="partbymonth" class="io.mycat.route.function.PartitionByMonth">
    <property name="dateFormat">yyyy-MM-dd</property>
    <property name="sBeginDate">2015-01-01</property>
</function>

起始日期2015-01-01到今天2017-07-11共30个月,需要30分片正常使用,将起始日期改为2017-07-01后正常,此时无法传入2017-07-01之前的数据,而且无法插入(起始日期+分片数量)之后月份的数据。即无法做到循环插入。

可使用以下规则做到按月循环插入,但是只能一个月一个表

<tableRule name="sharding-by-substring"> 
    <rule> 
        <columns>create_time</columns> 
        <algorithm>sharding-by-substring</algorithm> 
    </rule> 
</tableRule>
<function name="sharding-by-substring" 
    class="io.mycat.route.function.PartitionDirectBySubString"> 
    <property name="startIndex">5</property><!-- zero-based -->
    <property name="size">2</property> 
    <property name="partitionCount">12</property> 
    <property name="defaultPartition">0</property>
</function>

columns 标识将要分片的表字段,
algorithm 分片函数 此方法为直接根据字符子串(必须是数字)计算分区号(由应用传递参数,显式指定分区号)。
startIndex,截取开始位置,
size,截取长度,
partitionCount,分片数量,
defaultPartition,默认分片(截取到的不在分片数量内,则会按默认分片处理)

例如create_time=2017-07-04 17:30:03 在此配置中代表根据create_time中从startIndex=5开始,截取size=2位数字即07,07就是获取的分区,如果没有默认分配到defaultPartition

8.关于插入库名

​ 提供SQL插入语句时不要带库名,不然可能会全部插入一个库中

9.关于数据同步

mycat不提供数据同步,数据同步在MySQL中配置

10.关于主键

mycat不支持联合主键

  • 12
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

金山老师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值