Reputation: 26567
I need to save some link in mysql, but some link are smaller and others can be very bigger.
What field do I have to use in mysql ( varchar, TEXT, ecc ) ?
Upvotes: 6
Views: 13578
Reputation: 9794
Most url's with parameters will not be enough on varchar(255). Using Text which can take 65535 bytes will be enough.
TINYTEXT 256 bytes
TEXT 65,535 bytes ~64kb
MEDIUMTEXT 16,777,215 bytes ~16MB
LONGTEXT 4,294,967,295 bytes ~4GB
Edit: But If you are using mysql over 5.0.3 varchar (255) limitations are higher to 65535, so it is better to use like varchar(20000) for urls.
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used
Upvotes: 4
Reputation: 6148
Varchar is a good choice. TEXT is for vey large data and is stored outside the table. For more information read VARCHAR vs TEXT in MySQL
Upvotes: 7