Specified key was too long; max key length is 767 bytes
MySQL> use test; create table test(a varchar(512) primary key, b varchar(1024));
Database changed
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
drop table if exists test;
create table test(test varchar(767) primary key)charset=latin5;
-- 成功 drop table if exists test;
create table test(test varchar(768) primary key)charset=latin5;
-- 错误
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes drop table if exists test;
create table test(test varchar(383) primary key)charset=GBK;
-- 成功 drop table if exists test;
create table test(test varchar(384) primary key)charset=GBK;
-- 错误
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes drop table if exists test;
create table test(test varchar(255) primary key)charset=UTF8;
-- 成功 drop table if exists test;
create table test(test varchar(256) primary key)charset=UTF8;
-- 错误
-- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
原因:
MySQL的varchar主键只支持不超过768个字节,或者768/2=384个双字节,或者768/3=256个三字节的字段,而GBK是双字节的,UTF-8是三字节的。
变量设置:
mysql> show variables like '%char%';
+--------------------------+--------------------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /opt/schooner/ac_3.1/mysql/share/mysql/charsets/ |
+--------------------------+--------------------------------------------------+
8 rows in set (0.00 sec)
Specified key was too long; max key length is 767 bytes的更多相关文章
- 数据库操作提示:Specified key was too long; max key length is 767 bytes
操作重现: 法1:新建连接——>新建数据库——>右键数据库导入脚本——>提示:Specified key was too long; max key length is 767 by ...
- Mysql Specified key was too long; max key length is 767 bytes
今天导入一个数据库时,看到以下报错信息: Specified key was too bytes 直译就是索引键太长,最大为767字节. 查看sql库表文件,发现有一列定义如下: 列 名:cont ...
- Specified key was too long; max key length is 767 bytes mysql
Specified key was too long; max key length is 767 bytes 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该 ...
- Using innodb_large_prefix to avoid ERROR #1071,Specified key was too long; max key length is 1000 bytes
Using innodb_large_prefix to avoid ERROR 1071 单列索引限制上面有提到单列索引限制767,起因是256×3-1.这个3是字符最大占用空间(ut ...
- EF MySQL 提示 Specified key was too long; max key length is 767 bytes错误
在用EF的CodeFirst操作MySql时,提示 Specified key was too long; max key length is 767 bytes错误,但数据库和表也建成功了.有高人知 ...
- Specified key was too long; max key length is 767 b
alter table - engine=innodb,row_format=dynamic; Specified key was too long; max key length is 767 b
- MySQL错误“Specified key was too long; max key length is 1000 bytes”的解决办法
MySQL错误"Specified key was too long; max key length is 1000 bytes"的解决办法 经过查询才知道,是Mysql的字段设置 ...
- ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
今天在MySQL 5.6版本的数据库中修改InnoDB表字段长度时遇到了"ERROR 1071 (42000): Specified key was too long; max key le ...
- Specified key was too long; max key length is 767 bytes解决方案
问题描述: 1. 使用spark sql处理数据逻辑,逻辑处理后使用 df.write.mode(saveMode).jdbc(url, tableName, connectionPropertie ...
- laravel migrate时报错:Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
今天在学习laravel的路由模型绑定时,在按照文档执行php artisan migrate时报错. In Connection.php line 664: SQLSTATE[42000]: Syn ...
随机推荐
- Spark 调优(转)
Spark 调优 返回原文英文原文:Tuning Spark Because of the in-memory nature of most Spark computations, Spark pro ...
- 使用jsoup爬取所有成语
前几天看到有人在博问上求所有成语,想到刚好看了jsoup,就动手实践了一下,提问者给出了网站,一看很简单,就两种页面,一种是包含某个字的成语链接页面,一个是具体的包含某个字的成语的页面 下面是我的代码 ...
- Grafana分析Nginx日志
配置Groub by -Terms时报错,提示需要设置fielddata=true,报错内容大概如下: "Fielddata is disabled on text fields by de ...
- vscode 不显示指定后缀名pyc文件
不显示python生成的pyc文件 不显示java eclipse编辑器生成的.metadata生成的文件夹 py文件执行后会生成.pyc文件,会影响侧边栏的使用,可以通过如下设置隐藏.pyc等中间文 ...
- JSP页面中的小知识
1.<%…%>和<%!…%>的区别? <%…%>用于在JSP页面中嵌入Java脚本,即代码块 <%!…%>用于在JSP页面中申明变量或方法,可以在该页面 ...
- MVC异步控制器加载一个网页的所有内容
public void PageAsync() { AsyncManager.OutstandingOperations.Increment(); WebRequest req = WebReques ...
- HTML5 data属性
在HTML5中添加了data-*的方式来自定义属性,所谓data-*实际上上就是data-前缀加上自定义的属性名,命名可以用驼峰命名方式,但取值是必需全部使用小写,否则是undefinde 使用这样的 ...
- Flex Basis与Width的区别
[Flex Basis与Width的区别] Flex Items的应用准则 content –> width –> flex-basis (limted by max|min-width) ...
- asp.net 将数据导成Excel文件
思路:和word红头文件一样,采用xml格式的模板文件,再替换模板中设置好的标签就可以了.参考网址:http://www.cnblogs.com/tzy080112/p/3413938.html pu ...
- Hibernate一对多单向关联和双向关联映射方法及其优缺点 (待续)
一对多关联映射和多对一关联映射实现的基本原理都是一样的,既是在多的一端加入一个外键指向一的一端外键,而主要的区别就是维护端不同.它们的区别在于维护的关系不同: 一对多关联映射是指在加载一的一端数据的同 ...