I only get set the text field in MySQL to 255, if I want to store a data longer than 255 chars, what can I do?
我只将MySQL中的文本字段设置为255,如果我想存储长度超过255个字符的数据,我该怎么办?
4 个解决方案
#1
59
Prior to MySQL 5.0.3, a VARCHAR could only store up to 255 characters.
在MySQL 5.0.3之前,VARCHAR最多只能存储255个字符。
- To store up to 65535 (64KB) characters, use a TEXT column.
- 要存储最多65535(64KB)个字符,请使用TEXT列。
- To store up to 16777216 (16MB ) characters, use a MEDIUMTEXT column.
- 要存储最多16777216(16MB)字符,请使用MEDIUMTEXT列。
- To store up to 4294967296 (4GB) characters, use a LONGTEXT column.
- 要存储最多4294967296(4GB)字符,请使用LONGTEXT列。
See the storage requirements section of the manual for caveats on their usage.
有关其用法的警告,请参阅手册的存储要求部分。
Versions of MySQL after 5.0.3 can store up to 65535 chars in a VARCHAR (However you cannot store more than 65535 bytes in a single row).
5.0.3之后的MySQL版本可以在VARCHAR中存储多达65535个字符(但是,您不能在一行中存储超过65535个字节)。
#2
5
Use TEXT
datatype:
使用TEXT数据类型:
CREATE TABLE t_text (value TEXT NOT NULL);
INSERT
INTO t_text
SELECT RPAD('', 1000, '*');
SELECT LENGTH(value)
FROM t_text;
---
1000
#3
1
Change data type to varchar.
将数据类型更改为varchar。
#4
0
MySQL 4.0 -- Maximum length storage (Bytes) for String types:
MySQL 4.0 - String类型的最大长度存储(字节):
CHAR(255);
VARCHAR(255);
TINYBLOB, TINYTEXT < 2^8;
BLOB, TEXT < 2^16;
MEDIUMBLOB, MEDIUMTEXT < 2^24;
LONGBLOB, LONGTEXT < 2^32;
#1
59
Prior to MySQL 5.0.3, a VARCHAR could only store up to 255 characters.
在MySQL 5.0.3之前,VARCHAR最多只能存储255个字符。
- To store up to 65535 (64KB) characters, use a TEXT column.
- 要存储最多65535(64KB)个字符,请使用TEXT列。
- To store up to 16777216 (16MB ) characters, use a MEDIUMTEXT column.
- 要存储最多16777216(16MB)字符,请使用MEDIUMTEXT列。
- To store up to 4294967296 (4GB) characters, use a LONGTEXT column.
- 要存储最多4294967296(4GB)字符,请使用LONGTEXT列。
See the storage requirements section of the manual for caveats on their usage.
有关其用法的警告,请参阅手册的存储要求部分。
Versions of MySQL after 5.0.3 can store up to 65535 chars in a VARCHAR (However you cannot store more than 65535 bytes in a single row).
5.0.3之后的MySQL版本可以在VARCHAR中存储多达65535个字符(但是,您不能在一行中存储超过65535个字节)。
#2
5
Use TEXT
datatype:
使用TEXT数据类型:
CREATE TABLE t_text (value TEXT NOT NULL);
INSERT
INTO t_text
SELECT RPAD('', 1000, '*');
SELECT LENGTH(value)
FROM t_text;
---
1000
#3
1
Change data type to varchar.
将数据类型更改为varchar。
#4
0
MySQL 4.0 -- Maximum length storage (Bytes) for String types:
MySQL 4.0 - String类型的最大长度存储(字节):
CHAR(255);
VARCHAR(255);
TINYBLOB, TINYTEXT < 2^8;
BLOB, TEXT < 2^16;
MEDIUMBLOB, MEDIUMTEXT < 2^24;
LONGBLOB, LONGTEXT < 2^32;