MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length【转】
今天有开发反应他的建表语句错误,我看了下,提示:
MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length
原因是:
MySQL不允许在BLOB/TEXT,TINYBLOB, MEDIUMBLOB, LONGBLOB, TINYTEXT, MEDIUMTEXT, LONGTEXT,VARCHAR建索引,因为前面那些列类型都是可变长的,MySQL无法保证列的唯一性,只能在BLOB/TEXT前n个字节上建索引,这个n最大多长呢?做个测试:
root@test 03:53:58>create table lingluo_1 ( -> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(399))
-> )
-> COLLATE='gbk_chinese_ci'
-> ENGINE=InnoDB;
Query OK, 0 rows affected, 1 warning (0.00 sec) root@test 03:54:58>show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1071 | Specified key was too long; max key length is 767 bytes |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec) root@test 03:55:05>select 767/2;
+----------+
| 767/2 |
+----------+
| 383.5000 |
+----------+
1 row in set (0.00 sec)
root@test 03:55:47>create table lingluo_2 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(383))
-> )
-> COLLATE='gbk_chinese_ci'
-> ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec)
root@test 03:55:53>create table lingluo_3 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(383))
-> )
-> charset=utf8
-> ENGINE=InnoDB;
Query OK, 0 rows affected, 1 warning (0.00 sec) root@test 03:58:08>show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1071 | Specified key was too long; max key length is 767 bytes |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec) root@test 03:58:17>select 767/3;
+----------+
| 767/3 |
+----------+
| 255.6667 |
+----------+
1 row in set (0.00 sec) root@test 03:58:27>create table lingluo_4 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(255))
-> )
-> charset=utf8
-> ENGINE=InnoDB;
Query OK, 0 rows affected (0.02 sec) root@test 03:59:04>create table lingluo_5 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(256))
-> )
-> charset=utf8
-> ENGINE=InnoDB;
Query OK, 0 rows affected, 1 warning (0.01 sec) root@test 03:59:17>
root@test 03:59:17>show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1071 | Specified key was too long; max key length is 767 bytes |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec)
对于gbk(一个汉字占两个字节)编码的字段,只能前383个字符建索引;对于utf8(一个汉字占三个字节)编码的字段,只能前255个字符建索引;对于latin编码的字段,只能前767个字符建索引;
root@test 03:59:22>create table lingluo_6 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(768))
-> )
-> charset=latin1
-> ENGINE=InnoDB;
Query OK, 0 rows affected, 1 warning (0.01 sec) root@test 04:02:08>show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1071 | Specified key was too long; max key length is 767 bytes |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec) root@test 04:02:15>create table lingluo_7 (
-> id int(20) not null auto_increment,
-> aaa text,
-> primary key(id),
-> index idx_aaa(aaa(767))
-> )
-> charset=latin1
-> ENGINE=InnoDB;
Query OK, 0 rows affected (0.01 sec)
root@test 04:32:39>create table lingluo_8 ( id int(20) not null auto_increment, aaa varchar(10000), primary key(id), index idx_aaa(aaa) ) charset=latin1 ENGINE=InnoDB;
Query OK, 0 rows affected, 1 warning (0.01 sec) root@test 04:32:46>show warnings;
+---------+------+---------------------------------------------------------+
| Level | Code | Message |
+---------+------+---------------------------------------------------------+
| Warning | 1071 | Specified key was too long; max key length is 767 bytes |
+---------+------+---------------------------------------------------------+
1 row in set (0.00 sec)
同样的,当一个表里原来有非TEXT或者非BLOB字段(这些字段上有唯一索引或者普通索引)变为BLOB或TEXT的时候,也会遇到标题上的错误,如:
root@test 04:44:15>create table lingluo_10 (
-> id int(20) not null auto_increment,
-> aaa varchar(383),
-> primary key(id),
-> index idx_aaa(aaa)
-> )
-> charset=gbk
-> ENGINE=InnoDB;
Query OK, 0 rows affected (0.01 sec) root@test 04:44:39>alter table lingluo_10 modify aaa text;
ERROR 1170 (42000): BLOB/TEXT column 'aaa' used in key specification without a key length
转自
MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length - sunss - 博客园 https://www.cnblogs.com/sunss/archive/2012/05/17/2506396.html
mysql #1170错误(42000) BLOB/TEXT Column Used in Key Specification Without a Key Length - Thinkblog - CSDN博客 https://blog.csdn.net/BossDarcy/article/details/6209685
MySQL Error 1170 (42000): BLOB/TEXT Column Used in Key Specification Without a Key Length【转】的更多相关文章
- 1170 - BLOB/TEXT column 'CustomerName' used in key specification without a key length
[DTF] Data Transfer 企管宝_2_CRM start[DTF] Getting tables[DTF] Analyzing table: `CustomerInfo`[DTF] Ge ...
- [MySQL-1] mysql error 1101 blob/text column can't have a default value
在MySQL Query Browser上创建一个含有TEXT类型的字段,创建不成功,报错:mysql error 1101 blob/text column can't have a default ...
- pandas对象保存到mysql出错提示“BLOB/TEXT column used in key specification without a key length”解决办法
问题 将DataFrame数据保存到mysql中时,出现错误提示: BLOB/TEXT column used in key specification without a key length 原因 ...
- 操作MySQL出错提示“BLOB/TEXT column request_data in key specification without a key length”解决办法
错误原因: 查阅资料后才知道,原来Mysql数据库对于BLOB/TEXT这样类型的数据结构只能索引前N个字符.所以这样的数据类型不能作为主键,也不能是UNIQUE的.所以要换成VARCHAR,但是VA ...
- mysql联合索引阻碍修改列数据类型:BLOB/TEXT column 'name' used in key specification without a key length
今天在项目中mysql表中有一个字段数据类型为varchar,长度不够需要换为text类型 当时表是已经存在的表, CREATE TABLE `table_aaa` ( `id` int NOT NU ...
- 添加索引:BLOB/TEXT column 'xxx' used in key specification without a key length
问题 1. 将DataFrame数据保存到mysql后,添加索引出现错误提示: BLOB/TEXT column used in key specification without a key len ...
- 解决BLOB/TEXT column can't have a default value query问题
Create table的时候,报错BLOB/TEXT column 'xxxxxx( 表名称)' can't have a default value query ,意思是TEXT类型的表字段不能够 ...
- mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database
新安装的mysql密码是空的. ./mysql -u root -p use mysql SELECT `Host`,`User` FROM user; UPDATE user SET `Host` ...
- 基于mysql创建库的报错解决小记mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database
mysql ERROR 1044 (42000): Access denied for user ''@'localhost' to database异常处理 1.找到find / -name my. ...
随机推荐
- UEditor 在 Layer 模态框中无法使用问题
问题: 解决方法: 在 使用 ueditor 的页面顶部加入js代码: window.UEDITOR_HOME_URL = "__STATIC__/path/to/ueditor/&quo ...
- Django——Xadmin中的功能
app_label 功能 如果不在标准models.py里面定义model,则必须指定这个model归属于哪个app. 使用 app_label = 'oms' actions 功能 Action插件 ...
- excel将一个工作表根据条件拆分成多个sheet工作表与合并多个sheet工作表
本例介绍在excel中如何将一个工作表根据条件拆分成多个工作表. 注意:很多朋友反映sheets(i).delete这句代码出错,要注意下面第一个步骤,要拆分的数据工作表名称为“数据源”, 而不是你新 ...
- SWPUCTF 2019总结以及部分WP
本次SWPUCTF开赛了,一共做了5个misc+2个web,RE和Android没时间看= =,pwn完全不会,果然又是和去年一样划水.题目都出的很不错,做题的时候思路其实也容易想到,剩下几个web有 ...
- Kotlin对象表达式要点与Lambda表达式
Kotlin对象表达式要点揭密: 在上一次https://www.cnblogs.com/webor2006/p/11352421.html中学习了Kotlin的对象表达式,它主要是解决Java中匿名 ...
- 安装 uwsgi报错解决
背景: 安装 uwsgi时报错如下,查阅相关资料说是 python-devel的问题,于是安装之后python-devel后问题解决 报错如下: (venv) [xxxxxxx]# pip insta ...
- vscode——配置go插件
前言 这个真的折腾死我了,看了N多博客才弄好 这两个还是比较有用的~ https://www.cnblogs.com/nickchou/p/9038114.html https://www.jians ...
- ubuntu14.04 部署nfs服务
安装nfs服务 apt-get install nfs-kernel-server 修改配置文件,共享目录为/var/www,*号可替换为客户端IP地址,*默认为任何部署了nfs客户端的IP可以挂载该 ...
- Spring源码窥探之:Condition
采用注解的方式来注入bean 1. 编写config类 /** * @author 70KG * @Title: ConditionConfig * @Description: * @date 201 ...
- python中类的函数中的self
Python类中的self到底是干啥的 Python编写类的时候,每个函数参数第一个参数都是self,一开始我不管它到底是干嘛的,只知道必须要写上.后来对Python渐渐熟悉了一点,再回头看self的 ...