MySQL指定的密钥太长 [英] MySQL Specified key was too long

查看:239
本文介绍了MySQL指定的密钥太长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白我得到的错误.长度大于767的唯一字段是password,但它不是索引或任何内容.

I don't understand the error I'm getting. The only field longer than 767 is password but it's not an index or anything.

mysql> CREATE TABLE users (
    ->         id INTEGER NOT NULL AUTO_INCREMENT,
    ->         email VARCHAR(256) NOT NULL,
    ->         password VARCHAR(1024) NOT NULL,
    ->         date_added INTEGER,
    ->         PRIMARY KEY (id),
    ->         UNIQUE (email)
    -> );
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

推荐答案

VARCHAR(1024)

MySQL将VARCHAR值存储为1字节或2字节长的前缀以及数据.长度前缀指示值中的字节数.如果值要求不超过255个字节,则VARCHAR列将使用一个长度字节;如果值可能需要不超过255个字节,则VARCHAR列将使用两个长度字节.

MySQL stores VARCHAR values as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A VARCHAR column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.

在MySQL 5.0.3之前,长度指定大于 255 的VARCHAR列将转换为可以容纳给定长度值的最小TEXT类型.例如,VARCHAR(500)转换为TEXT,而VARCHAR(200000)转换为MEDIUMTEXT.

Prior to MySQL 5.0.3, a VARCHAR column with a length specification greater than 255 is converted to the smallest TEXT type that can hold values of the given length. For example, VARCHAR(500) is converted to TEXT, and VARCHAR(200000) is converted to MEDIUMTEXT.

参考: http://dev.mysql. com/doc/refman/5.0/en/string-type-overview.html

http://dev.mysql.com/doc/refman/5.0/en/char.html

这篇关于MySQL指定的密钥太长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆