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?
Storage Information : 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. Make sure you are aware of the effects of a multi-byte character set. VARCHAR(255) stores 255 characters, which may be more than 255 bytes.
The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters. The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255.
A TEXT column with a maximum length of 65,535 (216 − 1) characters. The effective maximum length is less if the value contains multibyte characters. Each TEXT value is stored using a 2-byte length prefix that indicates the number of bytes in the value.
LONGTEXT can store the maximum characters among all four, up to 4,294,967,295 characters i,e 4,294,967,295 bytes or 4GB. This is more than enough storage for any long-form text strings. For example, a book that MEDIUMTEXT can't hold can be stored using LONGTEXT. LONGTEXT takes 4-Bytes overhead.
Prior to MySQL 5.0.3, a VARCHAR could only store up to 255 characters.
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).
Use TEXT
datatype:
CREATE TABLE t_text (value TEXT NOT NULL);
INSERT
INTO t_text
SELECT RPAD('', 1000, '*');
SELECT LENGTH(value)
FROM t_text;
---
1000
Change data type to varchar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With