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 ...
随机推荐
- 尚硅谷springboot学习12-profile
一个项目对应不同的环境可以会有不同的配置,如开发,测试,生产环境使用不同的端口,这时可以设置profile变换不同的环境 通过spring.profiles.active切换环境 1.多Profile ...
- $event Object angularjs
You can pass the $event object as an argument when calling the function. The $event object contains ...
- 一个seq_file的小问题
在修改一个内核模块的时候,我们使用seq_file来打印我们的数据,结果非常出人意料. static void flowinfo_seq_printf_stats(struct seq_file *s ...
- monkey压力测试
压力测试: monkey -p com.qihu360.mobilesafe -v -p 后面跟包名 : -v 后面跟次数: 通过观察log日志,查看应用中出现的问题. =============== ...
- HBase 1.2.6 完全分布式集群安装部署详细过程
Apache HBase 是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,是NoSQL数据库,基于Google Bigtable思想的开源实现,可在廉价的PC Server上搭建大规模结构化存 ...
- Java中String的intern方法,javap&cfr.jar反编译,javap反编译后二进制指令代码详解,Java8常量池的位置
一个例子 public class TestString{ public static void main(String[] args){ String a = "a"; Stri ...
- centos7.5下yum 安装mariadb数据库
前言 mariadb 和mysql就像亲兄弟的关系,各种语法.驱动啥的,在mysql上能上的,在mariadb上基本都可以直接使用.更多的细节在此不多说. 1.删除旧版本 centos7下默认安装有m ...
- JVM G1GC参数配置
https://www.oracle.com/technetwork/articles/java/g1gc-1984535.html 主要这两个参数需要设置下,ParallelGCTh ...
- git gitlab 使用 提交代码解决冲突
1.更改完代码后,git push 发生错误 注: 此时,使用 git pull: 更新代码,git 会自动merge不同的更新, a. 如果git 自动merge成功,再进行 git push操作 ...
- Java的学习03
今天依然记录一下,学习情况,可以看到自己每一天都在进步. import java.text.DateFormat; import java.text.ParseException; import ja ...