4

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

xRobot
  • 25,579
  • 69
  • 184
  • 304

3 Answers3

5

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

Community
  • 1
  • 1
Tasawer Khan
  • 5,994
  • 7
  • 46
  • 69
4

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

Nesim Razon
  • 9,684
  • 3
  • 36
  • 48
  • downvote will be removed if you include varchar. PS: how can you forget about varchar? – ajreal Apr 22 '12 at 09:14
  • @Nesim varchar is not limited to 255 characters. I mean, it was, but now (version 5.0.3 or later) it can be bigger (1000 characters for example). That version was launched in the first half of 2005, let's assume that his version is not older than that... – Radu Murzea Apr 22 '12 at 09:16
  • So, is to use varchar(2000) the best way to save a link in mysql ? – xRobot Apr 22 '12 at 09:35
  • If your mysql version is over 5.0.3 best way to store is VARCHAR(2083) to be exactly. If your mysql version is lower than 5.0.3 than I suggest TEXT. – Nesim Razon Apr 22 '12 at 09:39
  • @NesimRazon I think you mean 2047, since 2 ^ 11 - 1 is 2047. I don't see any special significance to 2083. – Matteo C Aug 01 '16 at 19:04
  • 1
    @MatteoC 4 years later.. Maximum URL length is 2,083 characters in Internet Explorer https://support.microsoft.com/en-us/kb/208427 – Nesim Razon Aug 01 '16 at 19:34
2
varchar(255)

should work fine.

Arion
  • 31,011
  • 10
  • 70
  • 88
Alex G
  • 3,048
  • 10
  • 39
  • 78