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 ...
随机推荐
- MySQL null与not null和null与空值''的区别
参考连接:https://segmentfault.com/a/1190000009540449 相信很多用了MySQL很久的人,对这两个字段属性的概念还不是很清楚,一般会有以下疑问: 我字段类型是n ...
- UNITY2018.3 在editor下运行时new memoryprofiler显示 shader占用内存很大的问题在安卓上并没有看到
在安卓机上完全看不到shader占用的内存,但问题是,shader在安卓上真的几乎不占用内存了?(我们的游戏中只使用了mobile下的shader) 参考下面这个文章,说是真机上也有: Unity3D ...
- byte类型的127+1=-128?
public class Test2 { public void add(Byte b) { b = b++; } public void test() { Byte a = 127; Byte ...
- JDBC使用步骤分哪几步?
(1) 加载JDBC驱动程序: Cllass.forName(" 驱动程序" ); //你要连接的数据库对象 (2) 建立连接 Connection conn=DriverMa ...
- freemarker取数
在后端map必须的键值必须是字符串 java.util.Map busVoltagesMap = new java.util.HashMap(); busVoltagesMap.put("1 ...
- C# 图像处理: 获取当前活动窗口句柄,获取窗口大小及位置
需调用API函数 需在开头引入命名空间 using System.Runtime.InteropServices; 获取当前窗口句柄:GetForegroundWindow() [DllImport( ...
- ESET官方下载地址
官方远程下载 ESET NOD32 Antivirus(32位) ESET NOD32 Antivirus(64位) ESET Smart Security(32位) ESET Smart Secur ...
- C++读取txt和保存到txt
哇,今天又重新用C++来写了一些代码发现自己竟然在类的使用和文件读取和保存上面特别头疼,于是,各种问度娘+各种翻看之前的代码.不禁感叹,自己的代码还是写的太少了,对这些一点都不熟悉.于是,今晚!一定! ...
- 重新装kafka
Linux搭建kafka 一.安装Java 1.查看linux 的系统版本 root@aliyun:~# uname --m x86_64 2.安装java mkdir -p /usr/local ...
- Mat取行或列
Mat dst; dst = FeatureValue.colRange(j,j+).clone(); 直接使用Mat类中成员函数,方法,colRange对应的是列,rowRange对应的是行,从第j ...