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. ...
随机推荐
- python(if判断)
一.if判断 如果 条件满足,才能做某件事情, 如果 条件不满足,就做另外一件事情,或者什么也不做 注意: 代码的缩进为一个 tab 键,或者 4 个空格 在 Python 开发中,Tab 和空格不要 ...
- Android笔记(四十八) Android中的资源访问——SDCard
访问存储在SD卡中的文件 使用 Environment.getExternalStorageState(); 判断是否存在内存卡 使用 Environment.getExternalStorageDi ...
- angularcli 第一篇(新建、组件、模块)
1.新建并启动项目: 1.安装: npminstall -g @angular/cli 2.新建: ng new mytest 3.进入项目:cd mytest 4.启动: ng serve 5.打开 ...
- 加密类型、数据加密解密过程以及CA创建
对称加密算法 对称加密:加密和解密使用同一个密钥 DES:Data Encryption Standard,56bits 3DES: AES:Advanced (, , 256bits) Blowfi ...
- SCADA系统构架的安全分析总结
概念: SCADA 数据采集与监控 Supervisory Control And Data Acquisition .包括了计算机设备 工业控制组件 网络 组成部件 ,SCADA 系统被用 ...
- pom中添加插件打包上传源码
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> ...
- ISCC之msc_无法运行的exe
打开hxd,里面老长一串base64 解码试了一下,解出来是png文件头,但是图片有错误 百度了一下,PNG文件头是89 50 4E 47 0D 0A 1A 0A 再回去看 改成0A了事, 出来一张二 ...
- jvm整理
我 2.JVM内存区域 p{ text-align: center; font-size: 12px; margin: 4px 0 0 0; } .nav-thumb >div{ positio ...
- 51nod 2517 最少01翻转次数
小b有一个01序列,她每次可以翻转一个元素,即将该元素异或上1. 现在她希望序列不降,求最少翻转次数. 收起 输入 第一行输入一个数n,其中1≤n≤20000: 第二行输入一个由‘0’和‘1’组成 ...
- PHP——curl设置请求头需要注意哪些
前言 在设置这个请求头上踩了一些坑,此文记录下. 步骤 设置请求头 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 请求头写法 一定不要忘记:不然进行请求 ...