markzzz
markzzz

Reputation: 47945

How long can a hyperlink be?

On my website, an user can insert a hyperlink in a text input field. Then, this link (a string) is stored in my database.

On MySQL, the field that contains the hyperlink string is TEXT type, but I think its too long for this kind of information. Besides, VARCHAR(255) is too short sometimes.

What's the best type/length to store a hyperlink? It would be nice to know how long a link can be.

Upvotes: 4

Views: 3026

Answers (3)

WhiteFang34
WhiteFang34

Reputation: 72039

See: What is the maximum length of a URL in different browsers?

You could use VARCHAR(2048) if you want a lower limit. There's nothing wrong with using TEXT in terms of space though. In both cases they only use as much space as the text plus a few bytes to represent the length. See Data Type Storage Requirements for details.

As for whether or not you should pick VARCHAR or TEXT see: MySQL: Large VARCHAR vs. TEXT?

Upvotes: 2

BraedenP
BraedenP

Reputation: 7215

There is no limit to how long a hyperlink can be. Browsers limit the amount of data a GET request can send with a hyperlink, but there is no limit on how long the actual link itself can be.

A standard TEXT field will be fine for storing links (you won't suffer a performance hit for using that field as opposed to the VARCHAR(255) field type, nor will you use extra memory, so there's really no reason not to use it.)

Upvotes: 3

Cracker
Cracker

Reputation: 1768

HTTP does not specify any limit to the length of URLs. However, webservers and browsers may put a limit.

I guess some old IE versions have a limit of just around 250 characters.

Upvotes: 2

Related Questions