自从认识mysql的那天起就知道varchar的长度限制为255,不过现在这种情况已经改变了:
Values in VARCHAR
columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR
is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
In contrast to CHAR
, VARCHAR
values are stored as a one-byte or two-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.
...
The following table illustrates the differences between CHAR
and VARCHAR
by showing the result of storing various string values into CHAR(4)
and VARCHAR(4)
columns (assuming that the column uses a single-byte character set such as latin1
).
Value | CHAR(4) | Storage Required | VARCHAR(4) | Storage Required |
'' | ' ' | 4 bytes | '' | 1 byte |
'ab' | 'ab ' | 4 bytes | 'ab' | 3 bytes |
'abcd' | 'abcd' | 4 bytes | 'abcd' | 5 bytes |
'abcdefgh' | 'abcd' | 4 bytes | 'abcd' | 5 bytes |
(http://dev.mysql.com/doc/refman/5.1/en/char.html)
以后基本可以不使用text字段了。。。。。。