Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store more than 255 char in MySQL database?

Tags:

sql

mysql

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?

like image 394
DNB5brims Avatar asked Sep 25 '09 12:09

DNB5brims


People also ask

Is VARCHAR 255 the max?

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.

What is the maximum length of CHAR data type in MySQL?

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.

How many characters can MySQL hold?

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.

Can MySQL store large TEXT?

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.


Video Answer


3 Answers

Prior to MySQL 5.0.3, a VARCHAR could only store up to 255 characters.

  • To store up to 65535 (64KB) characters, use a TEXT column.
  • To store up to 16777216 (16MB ) characters, use a MEDIUMTEXT column.
  • To store up to 4294967296 (4GB) characters, use a LONGTEXT column.

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

like image 148
Paul Dixon Avatar answered Oct 13 '22 22:10

Paul Dixon


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
like image 45
Quassnoi Avatar answered Oct 13 '22 22:10

Quassnoi


Change data type to varchar.

like image 22
simon Avatar answered Oct 13 '22 22:10

simon