Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3281876
  • 博文数量: 815
  • 博客积分: 12898
  • 博客等级: 上将
  • 技术积分: 7883
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-25 09:57
文章分类

全部博文(815)

文章存档

2014年(1)

2011年(46)

2010年(192)

2009年(121)

2008年(70)

2007年(385)

分类: Mysql/postgreSQL

2009-06-19 05:42:56

--
-- 数据库: `wikidb`
--
-- --------------------------------------------------------
--
-- 表的结构 `job`
--
CREATE TABLE IF NOT EXISTS `job` (
`job_id` int( 9 ) unsigned NOT NULL AUTO_INCREMENT ,
`job_cmd` varchar( 255 ) NOT NULL DEFAULT '',
`job_namespace` int( 11 ) NOT NULL ,
`job_title` varchar( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL ,
`job_params` blob NOT NULL ,
PRIMARY KEY ( `job_id` ) ,
KEY `job_cmd` ( `job_cmd` , `job_namespace` , `job_title` )
) ENGINE = InnoDB DEFAULT CHARSET = utf8 AUTO_INCREMENT =1;

MySQL 返回:文档
#1071 - Specified key was too long; max key length is 1000 bytes


MySQL建立索引时,数据库计算key的长度是累加所有Index用到的字段的char长度后再按下面比例乘起来不能超过限定的key长度1000:
latin1 = 1 byte = 1 character
uft8 = 3 byte = 1 character
gbk = 2 byte = 1 character

这里的 job_cmd` varchar( 255 ) ,job_namespace` int( 11 ),job_title` varchar( 255 ) 采用 utf8
(255 + 11 +255) * 3 = 1563 > 1000,所有就会报1071错误



MySQL的varchar主键只支持不超过768个字节 或者 768/2=384个双字节 或者 768/3=256个三字节的字段
而 GBK是双字节的,UTF-8是三字节的。




Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.1.35-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 50
Server version: 5.1.35-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.



阅读(3304) | 评论(0) | 转发(0) |
0

上一篇:还会被放鸽子吗

下一篇:MySQL 密码

给主人留下些什么吧!~~