简体   繁体   中英

MySQL Specified key was too long

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 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.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM