Jbpm 4.3与mysql 6 的“Bug” :Specified key was too long; max key length is 767 bytes

 

 

环境:

mySql版本:6.0 Engine=InnoDB charset = utf8

 

语句:

create table JBPM4_EXECUTION (DBID_ bigint not null, CLASS_ varchar(255) not null, DBVERSION_ integer not null, ACTIVITYNAME_ varchar(255), PROCDEFID_ varchar(255), HASVARS_ bit, NAME_ varchar(255), KEY_ varchar(255), ID_ varchar(255) unique, STATE_ varchar(255), SUSPHISTSTATE_ varchar(255), PRIORITY_ integer, HISACTINST_ bigint, PARENT_ bigint, INSTANCE_ bigint, SUPEREXEC_ bigint, SUBPROCINST_ bigint, PARENT_IDX_ integer, primary key (DBID_))

 

错误:

17:14:37,805 SEV | [SchemaExport]:Specified key was too long; max key length is 767 bytes

 

资料:

Cause

The maximum key length for the MySQL database for InnoDB Engine is 767 bytes. The key length includes the sum lengths of all the columns included in the key.

Solutions

There are several solutions for this issue:

  • Changing the size of some columns. For example, if VARCHAR(300) is used to store last names, you can reduce its size to 100 with minimal risk of data loss.
  • Specifying the partial column length for the character columns in the key. For example, for VARCHAR(1000) column, you can specify only 100 characters to be used in the key.

        ALTER TABLE department

         ADD PRIMARY KEY (id, name(100));

In this example only 100 bytes of the NAME column participate in the primary key.

  • Using a different set of columns for the key.

参考:

http://www.ispirer.com/wiki/sqlways/troubleshooting-guide/mysql/import/key-too-long

也可以参考这个,了解一下引擎为myisaminnob的表对key最大长度的限制不一样:

http://yubowei.blog.51cto.com/978243/223773

 

从上面我们知道引擎为innodbMysqlkey最大长度为767bytes ,而在sql语句中我们这样设置的varchar(255),

 

1.        根据数据库字符编码:

MySQLvarchar主键只支持不超过768个字节 或者 768/2=384个双字节 或者 768/3=256个三字节的字段
GBK是双字节的,UTF-8是三字节的。(来自:http://www.java2000.net/p14993

根据《xml开发技术教程》中的编码详解:utf-8是变长编码,对于7位基本ASCII字符,仅用1一个字节;而其他字符使用1-3个字节编码,这么说来urf-8最多为3个字节。

2.        Mysql中数据类型varchar : String, length 0 - 255

“255*3=765<767” 我们看出varchar(255)所占的字节数肯定是没有超出最大长度的。

==============================================================================至此告一段落

 

接下来需要对mysqlkey的理解以及理解这句E文“The key length includes the sum lengths of all the columns included in the key.”

mysqlculomn key有如下几种:uni mul pri 等。(http://hlbng.iteye.com/blog/382457)

这句E文说的意思为:最大长度为所有key的长度之和。

 

回到sql语句:其中有两种keyuni pri ;一个为:primary key (DBID_) ,一个为ID_ varchar(255) unique

DBID_bigint类型,bigint 从 -2^63 (-9223372036854775808) 到 2^63-1 (9223372036854775807) 的整型数据(所有数字),存储大小为 8 个字节。(http://blog.csdn.net/Ivanluc/archive/2010/01/11/5174468.aspx 及其 http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

于是就有:“(255*3+8=  773  >  767” (原因所在:超过了最大长度)。

 

改成 “(252*3+8=  764  <  767” (所想解决办法)

create table JBPM4_EXECUTION (DBID_ bigint not null, CLASS_ varchar(255) not null, DBVERSION_ integer not null, ACTIVITYNAME_ varchar(255), PROCDEFID_ varchar(255), HASVARS_ bit, NAME_ varchar(255), KEY_ varchar(255), ID_ varchar(252) unique, STATE_ varchar(255), SUSPHISTSTATE_ varchar(255), PRIORITY_ integer, HISACTINST_ bigint, PARENT_ bigint, INSTANCE_ bigint, SUPEREXEC_ bigint, SUBPROCINST_ bigint, PARENT_IDX_ integer, primary key (DBID_));

错误:Specified key was too long; max key length is 767 bytes

 

反复查看这条sql语句,key只有这两个。

极限修改:将“ID_ varchar(252) unique 改成 ID_ varchar(20) unique 成功。

 

=========“(252*3+8=  764  <  767” 这个修改应该可以的========

 

兵临城下,解决问题再说,更改表的EngineInnoDB –> myisam

Set strorage_engine = myisam ;

存储引擎为myisam不支持事务管理。(http://taito.iteye.com/blog/314919

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值