ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.
MySQL版本5.6.35
在一个长度为512字符的字段上创建unique key报错
CREATE DATABASE dpcs_metadata DEFAULT CHARACTER SET utf8;
select * from information_schema.SCHEMATA;
+--------------+--------------------+----------------------------+------------------------+----------+
| CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH |
+--------------+--------------------+----------------------------+------------------------+----------+
| def | information_schema | utf8 | utf8_general_ci | NULL |
| def | dpcs_metadata | utf8 | utf8_general_ci | NULL |
| def | mysql | utf8 | utf8_bin | NULL |
| def | performance_schema | utf8 | utf8_general_ci | NULL |
| def | test | utf8 | utf8_bin | NULL |
+--------------+--------------------+----------------------------+------------------------+----------+
5 rows in set (0.00 sec) use dpcs_metadata; create table raw_log_meta_data(
id bigint NOT NULL AUTO_INCREMENT,
app_id varchar(64),
user_id varchar(128),
file_path varchar(512),
device_id varchar(128),
update_time DATETIME,
PRIMARY KEY (id),
UNIQUE KEY (user_id),
UNIQUE KEY (file_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
MySQL用1到2个额外字节记录该字段的长度,当字段长度小于等于255时使用1个字节记录字段长度,当长度大于255时使用2~4个字节记录字段长度,字段file_path的长度为512*3+2=1538个字节,超过系统默认767字节数限制
select * from information_schema.character_sets where character_set_name in('latin1', 'utf8', 'utf8mb4');
+--------------------+----------------------+----------------------+--------+
| CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN |
+--------------------+----------------------+----------------------+--------+
| latin1 | latin1_swedish_ci | cp1252 West European | 1 |
| utf8 | utf8_general_ci | UTF-8 Unicode | 3 |
| utf8mb4 | utf8mb4_general_ci | UTF-8 Unicode | 4 |
+--------------------+----------------------+----------------------+--------+
3 rows in set (0.00 sec)
根据上图所示,采用utf8编码的字段最大长度为255个字符时,255*3+1=756,是小于最大767限制的,可以创建成功,如下
create table raw_log_meta_data(
id bigint NOT NULL AUTO_INCREMENT,
app_id varchar(64),
user_id varchar(128),
file_path varchar(256),
device_id varchar(128),
update_time DATETIME,
PRIMARY KEY (id),
UNIQUE KEY (user_id),
UNIQUE KEY (file_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes create table raw_log_meta_data(
id bigint NOT NULL AUTO_INCREMENT,
app_id varchar(64),
user_id varchar(128),
file_path varchar(255),
device_id varchar(128),
update_time DATETIME,
PRIMARY KEY (id),
UNIQUE KEY (user_id),
UNIQUE KEY (file_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.19 sec) desc raw_log_meta_data;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| app_id | varchar(64) | YES | | NULL | |
| user_id | varchar(128) | YES | UNI | NULL | |
| file_path | varchar(255) | YES | UNI | NULL | |
| device_id | varchar(128) | YES | | NULL | |
| update_time | datetime | YES | | NULL | |
+-------------+--------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
根据文档所述
https://dev.mysql.com/doc/refman/5.6/en/create-index.html
Prefix support and lengths of prefixes (where supported) are storage engine dependent. For example, a prefix can be up to 767 bytes long for InnoDB tables or 3072 bytes if the innodb_large_prefix option is enabled. For MyISAM tables, the prefix length limit is 1000 bytes.
https://dev.mysql.com/doc/refman/5.6/en/innodb-parameters.html#sysvar_innodb_large_prefix
innodb_large_prefix
| Property | Value |
|---|---|
| Command-Line Format | --innodb-large-prefix[={OFF|ON}] |
| Introduced | 5.6.3 |
| System Variable | innodb_large_prefix |
| Scope | Global |
| Dynamic | Yes |
| Type | Boolean |
| Default Value | OFF |
Enable this option to allow index key prefixes longer than 767 bytes (up to 3072 bytes) for InnoDB tables that use DYNAMIC or COMPRESSED row format. (Creating such tables also requires the option values innodb_file_format=barracuda and innodb_file_per_table=true.) See Section 14.6.1.6, “Limits on InnoDB Tables” for maximums associated with index key prefixes under various settings.
For tables that use REDUNDANT or COMPACT row format, this option does not affect the permitted index key prefix length.
https://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html
By default, the index key prefix length limit is 767 bytes. See Section 13.1.13, “CREATE INDEX Syntax”. For example, you might hit this limit with a column prefix index of more than 255 characters on a TEXT or VARCHAR column, assuming a utf8mb3 character set and the maximum of 3 bytes for each character. When theinnodb_large_prefix configuration option is enabled, the index key prefix length limit is raised to 3072 bytes for InnoDB tables that use DYNAMIC or COMPRESSED row format.
根据以上可知,如果需要在长度大于255字符的字段上创建索引,需要修改以下3个参数
1. innodb_file_format=barracuda
3. ROW_FORMAT=DYNAMIC or COMPRESSED
mysql> show variables like 'innodb_large_prefix';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_large_prefix | OFF |
+---------------------+-------+
1 row in set (0.00 sec) mysql> show variables like 'innodb_file_format';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| innodb_file_format | Antelope |
+--------------------+----------+
1 row in set (0.00 sec) mysql> show variables like 'innodb_file_per_table';
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
1 row in set (0.00 sec) mysql> set global innodb_large_prefix='on';
Query OK, 0 rows affected (0.00 sec) mysql> set global innodb_file_format='Barracuda';
Query OK, 0 rows affected (0.00 sec) mysql> show variables like 'innodb_large_prefix';
+---------------------+-------+
| Variable_name | Value |
+---------------------+-------+
| innodb_large_prefix | ON |
+---------------------+-------+
1 row in set (0.00 sec) mysql> show variables like 'innodb_file_format';
+--------------------+-----------+
| Variable_name | Value |
+--------------------+-----------+
| innodb_file_format | Barracuda |
+--------------------+-----------+
1 row in set (0.00 sec)
create table raw_log_meta_data(
id bigint NOT NULL AUTO_INCREMENT,
app_id varchar(64),
user_id varchar(128),
file_path varchar(512),
device_id varchar(128),
update_time DATETIME,
PRIMARY KEY (id),
UNIQUE KEY (user_id),
UNIQUE KEY (file_path)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
Query OK, 0 rows affected (0.29 sec)
ERROR 1709 (HY000): Index column size too large. The maximum column size is 767 bytes.的更多相关文章
- mysql 1709: Index column size too large. The maximum column size is 767 bytes.
1709: Index column size too large. The maximum column size is 767 bytes. 修改排序规则解决 utf8_general_ci
- Index column size too large. The maximum column size is 767 bytes.
mysql建表时报Index column size too large. The maximum column size is 767 bytes.解决办法:在建表语句的后面加入:ENGINE=In ...
- Mysql [Err] 1118 - Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.
对于越来越多的数据,数据库的容量越来越大,压缩也就越来越常见了.在我的实际工作中进行过多次压缩工作,也遇到多次问题,在此和大家分享一下. 首先,我们先说说怎么使用innodb的压缩. 第一,mysql ...
- The maximum column size is 767 bytes (Mysql)
ERROR app.wsutils 419 INCRON: Error: ('HY000', '[HY000] [MySQL][ODBC 5.2(w) Driver][mysqld-5.7.7-rc ...
- MySQL Cluster测试过程中的错误汇总--ERROR 1296 (HY000)等等
参考资料: http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-privilege-distribution.html http://www.cl ...
- mysql 报Row size too large 65535 原因与解决方法
报错信息:Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535 ...
- Mysql_大字段问题Row size too large.....not counting BLOBs, is 8126.
[问题描述] 1.从myslq(5.7.19-0ubuntu0.16.04.1)中导出sql脚本,导入到mysql(5.5.27)中,报如下错误:Row size too large. The max ...
- mysql触发器应用和创建表错误代码: 1118 Row size too large. 解决
1.针对数据库查询问题的方便,可以建立重要表的log备份记录表,在主表的添加,修改,删除添加触发器,修改触发器增加触发字段的点,限制条件. 数据库log表查问题比从线上多台服务器上下载日志文件相对方便 ...
- Mysql [Err] 1118 - Row size too large
首先声明,对MySQL不懂,很多都不知道原因 设计了一个表,里面很多text字段,然后填进去的东西太多(用的是Python的MySQLdb),报错: _mysql_exceptions.Operati ...
随机推荐
- Python实现PDF文件截取
python3截取PDF文件中的一部分. from PyPDF2 import PdfFileWriter, PdfFileReader # 开始页 start_page = 0 # 截止页 end_ ...
- python6---购物车程序
#!/usr/bin/env python#_author: harry#date: 2019.11.12# -*- coding: utf-8 -*-product_list =[ ('mac',9 ...
- JS实现表格隔行变色
用到的鼠标事件:(1)鼠标经过 onmouseover:(2)鼠标离开 onmouseout 核心思路:鼠标经过 tr 行的时候,当前行会改变背景颜色,鼠标离开的时候去掉背景颜色. 注意:第一行(th ...
- inline元素导航栏案例
练习一个超链接元素在文档流当中,a标签显示出来的inline这种元素的特性.我们可以用display来将它转换成inline-block类型,这样我们就可以设置它的高度,宽度和它的背景颜色等等特性了. ...
- java8 base64编码和解码
package com.oy; import java.nio.charset.StandardCharsets; import java.util.Base64; import org.junit. ...
- Codeforces 932 E Team Work ( 第二类斯特林数、下降阶乘幂、组合数学 )
题目链接 题意 : 其实就是要求 分析 : 先暴力将次方通过第二类斯特林数转化成下降幂 ( 套路?) 然后再一步步化简.使得最外层和 N 有关的 ∑ 划掉 这里有个技巧就是 将组合数的表达式放到一边. ...
- Scratch的入门笔记
最近发现人工智能和编程在小学开始普及,由于好奇,所以开始去了解儿童编程方面的知识,希望增加一些儿童编程教育相关的知识面,跟上发展潮流. Scratch是一款由麻省理工学院的“终身幼儿园团队”(Life ...
- 2018 计蒜之道 初赛 第五场 A 贝壳找房搬家
贝壳找房换了一个全新的办公室,每位员工的物品都已经通过搬家公司打包成了箱子,搬进了新的办公室了,所有的箱子堆放在一间屋子里(这里所有的箱子都是相同的正方体),我们可以把这堆箱子看成一个 x*y*z 的 ...
- Vue-CLI项目搭建
一.环境搭建 1.安装服务器node 官网下载 https://nodejs.org/zh-cn/ node:用C++语言编写,用来运行JavaScript语言 node可以为前端项目提供server ...
- ar9331修改flash大小和df、cat /proc/mtd的区别
首先感谢黄工的指导. 在openwrt固件目录下target/linux/ar71xx/image/Makefile,找到对应的机型,修改为4M,8M,16M,32M. 以oolite机型为例,如图所 ...