Reputation: 1840
In a MySQL database, how would I set a varchar to have unlimited length, so that I can store long web pages? If not, then what is the Maximum Size?
I know about Text Types to store larger strings. Is there any limitations on using test data type which I have to handle?
Upvotes: 49
Views: 107413
Reputation: 1662
VARCHAR
can store upto 255 chars before MySQL 5.0.3 and 65,535 chars in 5.0.3 and later versions.
To store large data in MySQL database you can use TEXT
, MEDIUMTEXT
and LONGTEXT
data types:
TEXT can store 65,535 characters (approx 64KB)
MEDIUMTEXT = 16,777,215 characters (approx 16 MB)
LONGTEXT = 4,294,967,295 chars (approx 4GB)
Upvotes: 89
Reputation: 41
To answer the other part of his question ...
There can be all sorts of unforeseen limits depending on versions of software, data storage engine, etc.
I encountered these.
ALTER TABLE reportserver.report ADD reportquery varchar(65535)
Error Code: 1074. Column length too big for column 'reportquery' (max = 21845); use BLOB or TEXT instead
ALTER TABLE reportserver.report ADD reportquery varchar(21845)
Error Code: 1118. Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
You'd probably encounter these when setting up your table or not at all, but rather than risk not being able to add more columns, or not being able to make a column wider, you might want to go the TEXT route straight away if you have seriously wide columns.
Upvotes: 1
Reputation: 6132
you should try this method: refer this link:
alter table table_name modify col_name varchar(10000)
ALTER TABLE `table_name`
CHANGE COLUMN `col_name` `col_name` VARCHAR(10000);
or otherwise you should use this method:
TEXT can store 65,535 characters (approx 64KB)
MEDIUMTEXT = 16,777,215 characters (approx 16 MB)
LONGTEXT = 4,294,967,295 chars (approx 4GB)
Upvotes: 4
Reputation: 41
You can use varchar2. It is better than varchar in many ways
http://www.orafaq.com/faq/what_is_the_difference_between_varchar_varchar2_and_char_data_types
Or
You can try TEXT. It will work for you
Upvotes: -5